diff options
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/command.go | 26 | ||||
-rw-r--r-- | modules/git/commit.go | 6 | ||||
-rw-r--r-- | modules/git/git.go | 10 | ||||
-rw-r--r-- | modules/git/lfs.go | 2 | ||||
-rw-r--r-- | modules/git/repo.go | 4 |
5 files changed, 32 insertions, 16 deletions
diff --git a/modules/git/command.go b/modules/git/command.go index 3cf85c2d85..e8afaa0e46 100644 --- a/modules/git/command.go +++ b/modules/git/command.go @@ -20,8 +20,8 @@ import ( ) var ( - // GlobalCommandArgs global command args for external package setting - GlobalCommandArgs []string + // globalCommandArgs global command args for external package setting + globalCommandArgs []string // defaultCommandExecutionTimeout default command execution timeout duration defaultCommandExecutionTimeout = 360 * time.Second @@ -52,9 +52,9 @@ func NewCommand(args ...string) *Command { // NewCommandContext creates and returns a new Git Command based on given command and arguments. func NewCommandContext(ctx context.Context, args ...string) *Command { - // Make an explicit copy of GlobalCommandArgs, otherwise append might overwrite it - cargs := make([]string, len(GlobalCommandArgs)) - copy(cargs, GlobalCommandArgs) + // Make an explicit copy of globalCommandArgs, otherwise append might overwrite it + cargs := make([]string, len(globalCommandArgs)) + copy(cargs, globalCommandArgs) return &Command{ name: GitExecutable, args: append(cargs, args...), @@ -278,3 +278,19 @@ func (c *Command) RunTimeout(timeout time.Duration) (string, error) { func (c *Command) Run() (string, error) { return c.RunTimeout(-1) } + +// AllowLFSFiltersArgs return globalCommandArgs with lfs filter, it should only be used for tests +func AllowLFSFiltersArgs() []string { + // Now here we should explicitly allow lfs filters to run + filteredLFSGlobalArgs := make([]string, len(globalCommandArgs)) + j := 0 + for _, arg := range globalCommandArgs { + if strings.Contains(arg, "lfs") { + j-- + } else { + filteredLFSGlobalArgs[j] = arg + j++ + } + } + return filteredLFSGlobalArgs[:j] +} diff --git a/modules/git/commit.go b/modules/git/commit.go index 0ba53897f5..37b2e71cc0 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -84,7 +84,7 @@ 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 { - return AddChangesWithArgs(repoPath, GlobalCommandArgs, all, files...) + return AddChangesWithArgs(repoPath, globalCommandArgs, all, files...) } // AddChangesWithArgs marks local changes to be ready for commit. @@ -108,8 +108,8 @@ 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 { - cargs := make([]string, len(GlobalCommandArgs)) - copy(cargs, GlobalCommandArgs) + cargs := make([]string, len(globalCommandArgs)) + copy(cargs, globalCommandArgs) return CommitChangesWithArgs(repoPath, cargs, opts) } diff --git a/modules/git/git.go b/modules/git/git.go index 294d33f916..217e6955c2 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -134,21 +134,21 @@ func Init(ctx context.Context) error { } // force cleanup args - GlobalCommandArgs = []string{} + globalCommandArgs = []string{} if CheckGitVersionAtLeast("2.9") == nil { // Explicitly disable credential helper, otherwise Git credentials might leak - GlobalCommandArgs = append(GlobalCommandArgs, "-c", "credential.helper=") + globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=") } // Since git wire protocol has been released from git v2.18 if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil { - GlobalCommandArgs = append(GlobalCommandArgs, "-c", "protocol.version=2") + globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2") } // By default partial clones are disabled, enable them from git v2.22 if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil { - GlobalCommandArgs = append(GlobalCommandArgs, "-c", "uploadpack.allowfilter=true") + globalCommandArgs = append(globalCommandArgs, "-c", "uploadpack.allowfilter=true") } // Save current git version on init to gitVersion otherwise it would require an RWMutex @@ -213,7 +213,7 @@ func Init(ctx context.Context) error { if err := checkAndSetConfig("core.protectntfs", "false", true); err != nil { return err } - GlobalCommandArgs = append(GlobalCommandArgs, "-c", "core.protectntfs=false") + globalCommandArgs = append(globalCommandArgs, "-c", "core.protectntfs=false") } return nil } diff --git a/modules/git/lfs.go b/modules/git/lfs.go index 3a809d393d..cdd9d15b2e 100644 --- a/modules/git/lfs.go +++ b/modules/git/lfs.go @@ -29,7 +29,7 @@ func CheckLFSVersion() { logger.Error("LFS server support needs at least Git v2.1.2") } else { once.Do(func() { - GlobalCommandArgs = append(GlobalCommandArgs, "-c", "filter.lfs.required=", + globalCommandArgs = append(globalCommandArgs, "-c", "filter.lfs.required=", "-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=") }) } diff --git a/modules/git/repo.go b/modules/git/repo.go index 5636405118..663e13dc18 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -106,8 +106,8 @@ type CloneRepoOptions struct { // Clone clones original repository to target path. func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error { - cargs := make([]string, len(GlobalCommandArgs)) - copy(cargs, GlobalCommandArgs) + cargs := make([]string, len(globalCommandArgs)) + copy(cargs, globalCommandArgs) return CloneWithArgs(ctx, from, to, cargs, opts) } |