code: func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
  	if err := opts.Validate(w); err != nil {
  		return nil, err
  	}
  
  	// Obtain commit hash from options (CommitHash or ReferenceName).
  	var commitHash plumbing.Hash
  	// treeName contains the value of TreeName in GrepResult.
  	var treeName string
  
  	if opts.ReferenceName != "" {
  		ref, err := w.r.Reference(opts.ReferenceName, true)
  		if err != nil {
  			return nil, err
  		}
  		commitHash = ref.Hash()
  		treeName = opts.ReferenceName.String()
  	} else if !opts.CommitHash.IsZero() {
  		commitHash = opts.CommitHash
  		treeName = opts.CommitHash.String()
  	}
  
  	// Obtain a tree from the commit hash and get a tracked files iterator from
  	// the tree.
  	tree, err := w.getTreeFromCommitHash(commitHash)
  	if err != nil {
  		return nil, err
  	}
  	fileiter := tree.Files()
  
  	return findMatchInFiles(fileiter, treeName, opts)
  }
docs: // Grep performs grep on a worktree.