Fix datarace on git.GlobalCommandArgs on tests (#9162)
* fix datarace on git.GlobalCommandArgs on tests * fix tests * fix tests * fix tests
This commit is contained in:
@ -63,7 +63,6 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
|
||||
|
||||
func allowLFSFilters() []string {
|
||||
// Now here we should explicitly allow lfs filters to run
|
||||
globalArgs := git.GlobalCommandArgs
|
||||
filteredLFSGlobalArgs := make([]string, len(git.GlobalCommandArgs))
|
||||
j := 0
|
||||
for _, arg := range git.GlobalCommandArgs {
|
||||
@ -74,9 +73,7 @@ func allowLFSFilters() []string {
|
||||
j++
|
||||
}
|
||||
}
|
||||
filteredLFSGlobalArgs = filteredLFSGlobalArgs[:j]
|
||||
git.GlobalCommandArgs = filteredLFSGlobalArgs
|
||||
return globalArgs
|
||||
return filteredLFSGlobalArgs[:j]
|
||||
}
|
||||
|
||||
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
|
||||
@ -107,9 +104,7 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
|
||||
|
||||
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
oldGlobals := allowLFSFilters()
|
||||
assert.NoError(t, git.Clone(u.String(), dstLocalPath, git.CloneRepoOptions{}))
|
||||
git.GlobalCommandArgs = oldGlobals
|
||||
assert.NoError(t, git.CloneWithArgs(u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{}))
|
||||
assert.True(t, com.IsExist(filepath.Join(dstLocalPath, "README.md")))
|
||||
}
|
||||
}
|
||||
@ -170,9 +165,7 @@ func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
|
||||
|
||||
func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
oldGlobals := allowLFSFilters()
|
||||
_, err := git.NewCommand(append([]string{"checkout"}, args...)...).RunInDir(dstPath)
|
||||
git.GlobalCommandArgs = oldGlobals
|
||||
_, err := git.NewCommandNoGlobals(append(append(allowLFSFilters(), "checkout"), args...)...).RunInDir(dstPath)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
@ -186,9 +179,7 @@ func doGitMerge(dstPath string, args ...string) func(*testing.T) {
|
||||
|
||||
func doGitPull(dstPath string, args ...string) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
oldGlobals := allowLFSFilters()
|
||||
_, err := git.NewCommand(append([]string{"pull"}, args...)...).RunInDir(dstPath)
|
||||
git.GlobalCommandArgs = oldGlobals
|
||||
_, err := git.NewCommandNoGlobals(append(append(allowLFSFilters(), "pull"), args...)...).RunInDir(dstPath)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,8 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
|
||||
assert.NoError(t, err)
|
||||
err = git.AddChanges(dstPath, false, ".gitattributes")
|
||||
assert.NoError(t, err)
|
||||
oldGlobals := allowLFSFilters()
|
||||
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
|
||||
|
||||
err = git.CommitChangesWithArgs(dstPath, allowLFSFilters(), git.CommitChangesOptions{
|
||||
Committer: &git.Signature{
|
||||
Email: "user2@example.com",
|
||||
Name: "User Two",
|
||||
@ -163,7 +163,6 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
|
||||
Message: fmt.Sprintf("Testing commit @ %v", time.Now()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
git.GlobalCommandArgs = oldGlobals
|
||||
|
||||
littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix)
|
||||
|
||||
@ -307,12 +306,12 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
|
||||
|
||||
//Commit
|
||||
// Now here we should explicitly allow lfs filters to run
|
||||
oldGlobals := allowLFSFilters()
|
||||
err = git.AddChanges(repoPath, false, filepath.Base(tmpFile.Name()))
|
||||
globalArgs := allowLFSFilters()
|
||||
err = git.AddChangesWithArgs(repoPath, globalArgs, false, filepath.Base(tmpFile.Name()))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = git.CommitChanges(repoPath, git.CommitChangesOptions{
|
||||
err = git.CommitChangesWithArgs(repoPath, globalArgs, git.CommitChangesOptions{
|
||||
Committer: &git.Signature{
|
||||
Email: email,
|
||||
Name: fullName,
|
||||
@ -325,7 +324,6 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
|
||||
},
|
||||
Message: fmt.Sprintf("Testing commit @ %v", time.Now()),
|
||||
})
|
||||
git.GlobalCommandArgs = oldGlobals
|
||||
return filepath.Base(tmpFile.Name()), err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user