]> source.dussan.org Git - gitea.git/commit
Make gogit Repository.GetBranchNames consistent (#28348) (#28386)
authorGiteabot <teabot@gitea.io>
Thu, 7 Dec 2023 18:03:27 +0000 (02:03 +0800)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2023 18:03:27 +0000 (13:03 -0500)
commit272ae03341561ad51228fc75bd12ca3180504100
tree5605f0a2a79156cb1ce0a02e7cb542536a31c1a9
parentb56a9f6dedd7c689ff22c8fdd34c5761bbae3fe2
Make gogit Repository.GetBranchNames consistent (#28348) (#28386)

Backport #28348 by @AdamMajer

nogogit GetBranchNames() lists branches sorted in reverse commit date
order. On the other hand the gogit implementation doesn't apply any
ordering resulting in unpredictable behaviour. In my case, the unit
tests requiring particular order fail

    repo_branch_test.go:24:
                Error Trace:
               ./gitea/modules/git/repo_branch_test.go:24
                Error:          elements differ

                                extra elements in list A:
                                ([]interface {}) (len=1) {
                                 (string) (len=6) "master"
                                }

                                extra elements in list B:
                                ([]interface {}) (len=1) {
                                 (string) (len=7) "branch1"
                                }

                                listA:
                                ([]string) (len=2) {
                                 (string) (len=6) "master",
                                 (string) (len=7) "branch2"
                                }

                                listB:
                                ([]string) (len=2) {
                                 (string) (len=7) "branch1",
                                 (string) (len=7) "branch2"
                                }
                Test:           TestRepository_GetBranches

To fix this, we sort branches based on their commit date in gogit
implementation.

Fixes: #28318
Co-authored-by: Adam Majer <amajer@suse.de>
modules/git/repo_branch_gogit.go