MCPcopy Create free account
hub / github.com/go-git/go-git / TestGrepBare

Method TestGrepBare

worktree_test.go:2675–2754  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

2673}
2674
2675func (s *WorktreeSuite) TestGrepBare(c *C) {
2676 cases := []struct {
2677 name string
2678 options GrepOptions
2679 wantResult []GrepResult
2680 dontWantResult []GrepResult
2681 wantError error
2682 }{
2683 {
2684 name: "basic word match",
2685 options: GrepOptions{
2686 Patterns: []*regexp.Regexp{regexp.MustCompile("import")},
2687 CommitHash: plumbing.ZeroHash,
2688 },
2689 wantResult: []GrepResult{
2690 {
2691 FileName: "go/example.go",
2692 LineNumber: 3,
2693 Content: "import (",
2694 TreeName: "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
2695 },
2696 {
2697 FileName: "vendor/foo.go",
2698 LineNumber: 3,
2699 Content: "import \"fmt\"",
2700 TreeName: "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
2701 },
2702 },
2703 },
2704 }
2705
2706 path := fixtures.Basic().ByTag("worktree").One().Worktree().Root()
2707
2708 dir, clean := s.TemporalDir()
2709 defer clean()
2710
2711 r, err := PlainClone(dir, true, &CloneOptions{
2712 URL: path,
2713 })
2714 c.Assert(err, IsNil)
2715
2716 for _, tc := range cases {
2717 gr, err := r.Grep(&tc.options)
2718 if tc.wantError != nil {
2719 c.Assert(err, Equals, tc.wantError)
2720 } else {
2721 c.Assert(err, IsNil)
2722 }
2723
2724 // Iterate through the results and check if the wanted result is present
2725 // in the got result.
2726 for _, wantResult := range tc.wantResult {
2727 found := false
2728 for _, gotResult := range gr {
2729 if wantResult == gotResult {
2730 found = true
2731 break
2732 }

Callers

nothing calls this directly

Calls 5

PlainCloneFunction · 0.85
RootMethod · 0.80
WorktreeMethod · 0.80
TemporalDirMethod · 0.80
GrepMethod · 0.45

Tested by

no test coverage detected