aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--repository/gogit.go34
-rw-r--r--repository/gogit_test.go2
2 files changed, 27 insertions, 9 deletions
diff --git a/repository/gogit.go b/repository/gogit.go
index 78bae1f9..a93e8576 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -453,24 +453,42 @@ func (repo *GoGitRepo) RefExist(ref string) (bool, error) {
}
func (repo *GoGitRepo) CopyRef(source string, dest string) error {
- return repo.r.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName(dest), plumbing.NewHash(source)))
+ r, err := repo.r.Reference(plumbing.ReferenceName(source), false)
+ if err != nil {
+ return err
+ }
+ return repo.r.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName(dest), r.Hash()))
}
func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) {
- commitIter, err := repo.r.CommitObjects()
+ r, err := repo.r.Reference(plumbing.ReferenceName(ref), false)
if err != nil {
return nil, err
}
- var commits []Hash
-
- err = commitIter.ForEach(func(commit *object.Commit) error {
- commits = append(commits, Hash(commit.Hash.String()))
- return nil
- })
+ commit, err := repo.r.CommitObject(r.Hash())
if err != nil {
return nil, err
}
+ commits := []Hash{Hash(commit.Hash.String())}
+
+ for {
+ commit, err = commit.Parent(0)
+
+ if err != nil {
+ if err == object.ErrParentNotFound {
+ break
+ }
+
+ return nil, err
+ }
+
+ if commit.NumParents() > 1 {
+ return nil, fmt.Errorf("multiple parents")
+ }
+
+ commits = append(commits, Hash(commit.Hash.String()))
+ }
return commits, nil
}
diff --git a/repository/gogit_test.go b/repository/gogit_test.go
index 9dcf109f..fba990d3 100644
--- a/repository/gogit_test.go
+++ b/repository/gogit_test.go
@@ -58,7 +58,7 @@ func TestNewGoGitRepo(t *testing.T) {
require.Error(t, err, i)
} else {
require.NoError(t, err, i)
- assert.Equal(t, tc.outPath, r.GetPath(), i)
+ assert.Equal(t, filepath.ToSlash(tc.outPath), filepath.ToSlash(r.GetPath()), i)
}
}
}