mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
fix ListCommits implementation
This commit is contained in:
parent
d4f1d5659b
commit
27e70af236
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user