test: repo_branch_test.go is flaky #12135

Closed
opened 2025-11-02 09:59:29 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @AdamMajer on GitHub (Dec 1, 2023).

Description

Every time I run this test, it seems to fail locally but succeed remotely.

2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: -test                                 
2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: --test                                
61ab7345a1a3bbc590068ccae37b8515cfc5843c                                                       
61ab7345a1a3bbc590068ccae37b8515cfc5843c                                                       
--- FAIL: TestRepository_GetBranches (0.00s)                                                                                                                                                  
    repo_branch_test.go:24:                                                                    
                Error Trace:    /home/adamm/work/alp/gitea/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
FAIL
Test failed: run test failed, ExitCode=1
FAIL    code.gitea.io/gitea/modules/git 0.464s

Gitea Version

main

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

git version 2.43.0

Operating System

openSUSE Tumbleweed

How are you running Gitea?

N/A

Database

None

Originally created by @AdamMajer on GitHub (Dec 1, 2023). ### Description Every time I run this test, it seems to fail locally but succeed remotely. ``` 2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: -test 2023/12/01 13:55:50 ...dules/git/command.go:275:Run() [E] git command is broken: /usr/bin/git -c protocol.version=2 -c credential.helper=, broken args: --test 61ab7345a1a3bbc590068ccae37b8515cfc5843c 61ab7345a1a3bbc590068ccae37b8515cfc5843c --- FAIL: TestRepository_GetBranches (0.00s) repo_branch_test.go:24: Error Trace: /home/adamm/work/alp/gitea/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 FAIL Test failed: run test failed, ExitCode=1 FAIL code.gitea.io/gitea/modules/git 0.464s ``` ### Gitea Version main ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version git version 2.43.0 ### Operating System openSUSE Tumbleweed ### How are you running Gitea? N/A ### Database None
GiteaMirror added the type/bug label 2025-11-02 09:59:29 -06:00
Author
Owner

@lng2020 commented on GitHub (Dec 4, 2023):

I can test it locally. Have you tried to figure out why you failed? You may inspect the bare repo under modules/git/tests/repos/repo1_bare.

Running tool: /usr/bin/go test -timeout 30s -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git -tags sqlite,sqlite_unlock_notify -v

=== RUN   TestRepository_GetBranches
--- PASS: TestRepository_GetBranches (0.01s)
PASS
ok  	code.gitea.io/gitea/modules/git	0.124s
@lng2020 commented on GitHub (Dec 4, 2023): I can test it locally. Have you tried to figure out why you failed? You may inspect the bare repo under `modules/git/tests/repos/repo1_bare`. ``` Running tool: /usr/bin/go test -timeout 30s -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git -tags sqlite,sqlite_unlock_notify -v === RUN TestRepository_GetBranches --- PASS: TestRepository_GetBranches (0.01s) PASS ok code.gitea.io/gitea/modules/git 0.124s ```
Author
Owner

@lunny commented on GitHub (Dec 4, 2023):

Maybe you can check your git config under gitea's home directory.

@lunny commented on GitHub (Dec 4, 2023): Maybe you can check your git config under gitea's home directory.
Author
Owner

@AdamMajer commented on GitHub (Dec 4, 2023):

It seems it's gogit related. I assume it's assuming that there is some order to git branch listing. Is there suppose to be one?

> /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git
ok      code.gitea.io/gitea/modules/git (cached)


> /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify,gogit -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git
--- FAIL: TestRepository_GetBranches (0.00s)
    repo_branch_test.go:24: 
                Error Trace:    /home/adamm/work/alp/gitea/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
FAIL
Test failed: run test failed, ExitCode=1
FAIL    code.gitea.io/gitea/modules/git 0.066s
FAIL
@AdamMajer commented on GitHub (Dec 4, 2023): It seems it's `gogit` related. I assume it's assuming that there is some order to git branch listing. Is there suppose to be one? ``` > /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git ok code.gitea.io/gitea/modules/git (cached) > /usr/bin/go test -timeout 30s -tags sqlite,sqlite_unlock_notify,gogit -run ^TestRepository_GetBranches$ code.gitea.io/gitea/modules/git --- FAIL: TestRepository_GetBranches (0.00s) repo_branch_test.go:24: Error Trace: /home/adamm/work/alp/gitea/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 FAIL Test failed: run test failed, ExitCode=1 FAIL code.gitea.io/gitea/modules/git 0.066s FAIL ```
Author
Owner

@AdamMajer commented on GitHub (Dec 4, 2023):

Maybe you can check your git config under gitea's home directory.

It's just gitea checkout. The failure only happens with gogit. I have v5@v5.9.0 which seems to be what gitea requires anyway.

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
@AdamMajer commented on GitHub (Dec 4, 2023): > Maybe you can check your git config under gitea's home directory. It's just gitea checkout. The failure only happens with gogit. I have v5@v5.9.0 which seems to be what gitea requires anyway. ``` [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ```
Author
Owner

@lng2020 commented on GitHub (Dec 4, 2023):

Yes. It's about the file sequence in gogit. PR to make this test more robust is welcome.

@lng2020 commented on GitHub (Dec 4, 2023): Yes. It's about the file sequence in gogit. PR to make this test more robust is welcome.
Author
Owner

@AdamMajer commented on GitHub (Dec 4, 2023):

Looking at the nogogit implementation,

// GetBranchNames returns branches from the repository, skipping "skip" initial branches and
// returning at most "limit" branches, or all branches if "limit" is 0.
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
	return callShowRef(repo.Ctx, repo.Path, BranchPrefix, TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}, skip, limit)
}

which means the problem is not gogit itself, it's more the expectation of sort order. This also hints at the solution.

@AdamMajer commented on GitHub (Dec 4, 2023): Looking at the nogogit implementation, ``` // GetBranchNames returns branches from the repository, skipping "skip" initial branches and // returning at most "limit" branches, or all branches if "limit" is 0. func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) { return callShowRef(repo.Ctx, repo.Path, BranchPrefix, TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}, skip, limit) } ``` which means the problem is not gogit itself, it's more the expectation of sort order. This also hints at the solution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12135