aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-09-08 14:31:40 +0200
committerMichael Muré <batolettre@gmail.com>2020-09-29 20:42:21 +0200
commitd4f1d5659b9d23ff0768ed584ae320cb657c6f2d (patch)
tree0a076c74910690330438e6437ec6b58c437cc2b2 /repository/gogit.go
parentbde93756321b7a5eb0ec013e059914528b7c2610 (diff)
downloadgit-bug-d4f1d5659b9d23ff0768ed584ae320cb657c6f2d.tar.gz
repo: fix some go-git implementation
Diffstat (limited to 'repository/gogit.go')
-rw-r--r--repository/gogit.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/repository/gogit.go b/repository/gogit.go
index bd8ada33..78bae1f9 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -7,6 +7,7 @@ import (
"os"
stdpath "path"
"path/filepath"
+ "strings"
"sync"
"time"
@@ -420,7 +421,7 @@ func (repo *GoGitRepo) RemoveRef(ref string) error {
return repo.r.Storer.RemoveReference(plumbing.ReferenceName(ref))
}
-func (repo *GoGitRepo) ListRefs(refspec string) ([]string, error) {
+func (repo *GoGitRepo) ListRefs(refPrefix string) ([]string, error) {
refIter, err := repo.r.References()
if err != nil {
return nil, err
@@ -428,9 +429,16 @@ func (repo *GoGitRepo) ListRefs(refspec string) ([]string, error) {
refs := make([]string, 0)
- for ref, _ := refIter.Next(); ref != nil; {
- refs = append(refs, ref.String()) // TODO: Use format to search
+ err = refIter.ForEach(func(ref *plumbing.Reference) error {
+ if strings.HasPrefix(ref.Name().String(), refPrefix) {
+ refs = append(refs, ref.Name().String())
+ }
+ return nil
+ })
+ if err != nil {
+ return nil, err
}
+
return refs, nil
}
@@ -454,10 +462,16 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) {
return nil, err
}
- var commits []Hash // TODO: Implement refspec
- for commit, _ := commitIter.Next(); commit != nil; {
+ var commits []Hash
+
+ err = commitIter.ForEach(func(commit *object.Commit) error {
commits = append(commits, Hash(commit.Hash.String()))
+ return nil
+ })
+ if err != nil {
+ return nil, err
}
+
return commits, nil
}