MCPcopy
hub / github.com/go-git/go-git / Grep

Method Grep

worktree.go:900–931  ·  view source on GitHub ↗

Grep performs grep on a repository.

(opts *GrepOptions)

Source from the content-addressed store, hash-verified

898
899// Grep performs grep on a repository.
900func (r *Repository) Grep(opts *GrepOptions) ([]GrepResult, error) {
901 if err := opts.validate(r); err != nil {
902 return nil, err
903 }
904
905 // Obtain commit hash from options (CommitHash or ReferenceName).
906 var commitHash plumbing.Hash
907 // treeName contains the value of TreeName in GrepResult.
908 var treeName string
909
910 if opts.ReferenceName != "" {
911 ref, err := r.Reference(opts.ReferenceName, true)
912 if err != nil {
913 return nil, err
914 }
915 commitHash = ref.Hash()
916 treeName = opts.ReferenceName.String()
917 } else if !opts.CommitHash.IsZero() {
918 commitHash = opts.CommitHash
919 treeName = opts.CommitHash.String()
920 }
921
922 // Obtain a tree from the commit hash and get a tracked files iterator from
923 // the tree.
924 tree, err := r.getTreeFromCommitHash(commitHash)
925 if err != nil {
926 return nil, err
927 }
928 fileiter := tree.Files()
929
930 return findMatchInFiles(fileiter, treeName, opts)
931}
932
933// Grep performs grep on a worktree.
934func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {

Callers

nothing calls this directly

Calls 8

ReferenceMethod · 0.95
getTreeFromCommitHashMethod · 0.95
findMatchInFilesFunction · 0.85
HashMethod · 0.65
StringMethod · 0.65
IsZeroMethod · 0.65
FilesMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected