diff options
author | Michael Muré <batolettre@gmail.com> | 2020-09-29 20:16:15 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-09-29 20:43:54 +0200 |
commit | 4055495c8ba983033459507f3032ca93c6ec006a (patch) | |
tree | 852ba5a688eea6872b0885d23dc91342d09b468d /repository | |
parent | 0acb3505ffe71718cb3b6b0e957cc921ea9ce880 (diff) | |
download | git-bug-4055495c8ba983033459507f3032ca93c6ec006a.tar.gz |
repo: fix wrong ordering in gogit's ListCommit
Diffstat (limited to 'repository')
-rw-r--r-- | repository/gogit.go | 14 | ||||
-rw-r--r-- | repository/repo_testing.go | 2 |
2 files changed, 7 insertions, 9 deletions
diff --git a/repository/gogit.go b/repository/gogit.go index aac89d4b..09f714ea 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -536,16 +536,14 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) { if err != nil { return nil, err } - commits := []Hash{Hash(commit.Hash.String())} + hashes := []Hash{Hash(commit.Hash.String())} for { commit, err = commit.Parent(0) - + if err == object.ErrParentNotFound { + break + } if err != nil { - if err == object.ErrParentNotFound { - break - } - return nil, err } @@ -553,10 +551,10 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) { return nil, fmt.Errorf("multiple parents") } - commits = append(commits, Hash(commit.Hash.String())) + hashes = append([]Hash{Hash(commit.Hash.String())}, hashes...) } - return commits, nil + return hashes, nil } // GetOrCreateClock return a Lamport clock stored in the Repo. diff --git a/repository/repo_testing.go b/repository/repo_testing.go index b1f47396..41b3609e 100644 --- a/repository/repo_testing.go +++ b/repository/repo_testing.go @@ -188,7 +188,7 @@ func RepoDataTest(t *testing.T, repo RepoData) { commits, err := repo.ListCommits("refs/bugs/ref2") require.NoError(t, err) - require.ElementsMatch(t, []Hash{commit1, commit2}, commits) + require.Equal(t, []Hash{commit1, commit2}, commits) // Graph |