Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gogit Repository.GetBranchNames consistent (#28348) #28386

Merged

Conversation

GiteaBot
Copy link
Contributor

@GiteaBot GiteaBot commented Dec 7, 2023

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

@GiteaBot GiteaBot added type/bug lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 7, 2023
@GiteaBot GiteaBot added this to the 1.21.2 milestone Dec 7, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 7, 2023
@techknowlogick techknowlogick merged commit 272ae03 into go-gitea:release/v1.21 Dec 7, 2023
25 of 26 checks passed
@techknowlogick techknowlogick deleted the backport-28348-v1.21 branch December 7, 2023 18:03
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants