aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-04-26 18:28:51 +0100
committerGitHub <noreply@github.com>2023-04-26 18:28:51 +0100
commit0542a302c2be7ed7de276411f7e20b87309734b9 (patch)
treead051d5540425a2df69e5fdee07ddd32b6d64316 /worktree.go
parentcd1fd6b5da926e8dedd776b319455e499e35618b (diff)
parent3aa7575a4d660a250edd06864d6401a302951fab (diff)
downloadgo-git-0542a302c2be7ed7de276411f7e20b87309734b9.tar.gz
Merge pull request #728 from aymanbagabas/grep-bare
fix: git grep bare repositories
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/worktree.go b/worktree.go
index d28ba32..7d2f3b4 100644
--- a/worktree.go
+++ b/worktree.go
@@ -290,7 +290,7 @@ func (w *Worktree) ResetSparsely(opts *ResetOptions, dirs []string) error {
return nil
}
- t, err := w.getTreeFromCommitHash(opts.Commit)
+ t, err := w.r.getTreeFromCommitHash(opts.Commit)
if err != nil {
return err
}
@@ -633,8 +633,8 @@ func (w *Worktree) addIndexFromFile(name string, h plumbing.Hash, idx *indexBuil
return nil
}
-func (w *Worktree) getTreeFromCommitHash(commit plumbing.Hash) (*object.Tree, error) {
- c, err := w.r.CommitObject(commit)
+func (r *Repository) getTreeFromCommitHash(commit plumbing.Hash) (*object.Tree, error) {
+ c, err := r.CommitObject(commit)
if err != nil {
return nil, err
}
@@ -802,9 +802,9 @@ func (gr GrepResult) String() string {
return fmt.Sprintf("%s:%s:%d:%s", gr.TreeName, gr.FileName, gr.LineNumber, gr.Content)
}
-// Grep performs grep on a worktree.
-func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
- if err := opts.Validate(w); err != nil {
+// Grep performs grep on a repository.
+func (r *Repository) Grep(opts *GrepOptions) ([]GrepResult, error) {
+ if err := opts.validate(r); err != nil {
return nil, err
}
@@ -814,7 +814,7 @@ func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
var treeName string
if opts.ReferenceName != "" {
- ref, err := w.r.Reference(opts.ReferenceName, true)
+ ref, err := r.Reference(opts.ReferenceName, true)
if err != nil {
return nil, err
}
@@ -827,7 +827,7 @@ func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
// Obtain a tree from the commit hash and get a tracked files iterator from
// the tree.
- tree, err := w.getTreeFromCommitHash(commitHash)
+ tree, err := r.getTreeFromCommitHash(commitHash)
if err != nil {
return nil, err
}
@@ -836,6 +836,11 @@ func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
return findMatchInFiles(fileiter, treeName, opts)
}
+// Grep performs grep on a worktree.
+func (w *Worktree) Grep(opts *GrepOptions) ([]GrepResult, error) {
+ return w.r.Grep(opts)
+}
+
// findMatchInFiles takes a FileIter, worktree name and GrepOptions, and
// returns a slice of GrepResult containing the result of regex pattern matching
// in content of all the files.