diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-27 08:35:52 +0800 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-11-27 01:35:52 +0100 |
commit | 7b7d382b8b414e7da67dfec7c7e1ef9e0e269d68 (patch) | |
tree | ea2bd9ccb5ba69da61fbf463c4f87409e98307b7 /modules/git/commit.go | |
parent | 9d9e6ac4117b8efd2f85fc625a4ccfdcf73c4fc3 (diff) | |
download | gitea-7b7d382b8b414e7da67dfec7c7e1ef9e0e269d68.tar.gz gitea-7b7d382b8b414e7da67dfec7c7e1ef9e0e269d68.zip |
Fix datarace on git.GlobalCommandArgs on tests (#9162)
* fix datarace on git.GlobalCommandArgs on tests
* fix tests
* fix tests
* fix tests
Diffstat (limited to 'modules/git/commit.go')
-rw-r--r-- | modules/git/commit.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go index ce55dd55f6..0388d5e9be 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -207,7 +207,12 @@ func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { // AddChanges marks local changes to be ready for commit. func AddChanges(repoPath string, all bool, files ...string) error { - cmd := NewCommand("add") + return AddChangesWithArgs(repoPath, GlobalCommandArgs, all, files...) +} + +// AddChangesWithArgs marks local changes to be ready for commit. +func AddChangesWithArgs(repoPath string, gloablArgs []string, all bool, files ...string) error { + cmd := NewCommandNoGlobals(append(gloablArgs, "add")...) if all { cmd.AddArguments("--all") } @@ -226,7 +231,15 @@ type CommitChangesOptions struct { // CommitChanges commits local changes with given committer, author and message. // If author is nil, it will be the same as committer. func CommitChanges(repoPath string, opts CommitChangesOptions) error { - cmd := NewCommand() + cargs := make([]string, len(GlobalCommandArgs)) + copy(cargs, GlobalCommandArgs) + return CommitChangesWithArgs(repoPath, cargs, opts) +} + +// CommitChangesWithArgs commits local changes with given committer, author and message. +// If author is nil, it will be the same as committer. +func CommitChangesWithArgs(repoPath string, args []string, opts CommitChangesOptions) error { + cmd := NewCommandNoGlobals(args...) if opts.Committer != nil { cmd.AddArguments("-c", "user.name="+opts.Committer.Name, "-c", "user.email="+opts.Committer.Email) } |