@@ -21,6 +21,7 @@ import (
21
21
"code.gitea.io/gitea/models/perm"
22
22
"code.gitea.io/gitea/models/repo"
23
23
"code.gitea.io/gitea/modules/git"
24
+ "code.gitea.io/gitea/modules/git/gitcmd"
24
25
"code.gitea.io/gitea/modules/json"
25
26
"code.gitea.io/gitea/modules/lfstransfer"
26
27
"code.gitea.io/gitea/modules/log"
@@ -312,30 +313,30 @@ func runServ(ctx context.Context, c *cli.Command) error {
312
313
return nil
313
314
}
314
315
315
- var gitcmd * exec.Cmd
316
- gitBinPath := filepath .Dir (git .GitExecutable ) // e.g. /usr/bin
317
- gitBinVerb := filepath .Join (gitBinPath , verb ) // e.g. /usr/bin/git-upload-pack
316
+ var command * exec.Cmd
317
+ gitBinPath := filepath .Dir (gitcmd .GitExecutable ) // e.g. /usr/bin
318
+ gitBinVerb := filepath .Join (gitBinPath , verb ) // e.g. /usr/bin/git-upload-pack
318
319
if _ , err := os .Stat (gitBinVerb ); err != nil {
319
320
// if the command "git-upload-pack" doesn't exist, try to split "git-upload-pack" to use the sub-command with git
320
321
// ps: Windows only has "git.exe" in the bin path, so Windows always uses this way
321
322
verbFields := strings .SplitN (verb , "-" , 2 )
322
323
if len (verbFields ) == 2 {
323
324
// use git binary with the sub-command part: "C:\...\bin\git.exe", "upload-pack", ...
324
- gitcmd = exec .CommandContext (ctx , git .GitExecutable , verbFields [1 ], repoPath )
325
+ command = exec .CommandContext (ctx , gitcmd .GitExecutable , verbFields [1 ], repoPath )
325
326
}
326
327
}
327
- if gitcmd == nil {
328
+ if command == nil {
328
329
// by default, use the verb (it has been checked above by allowedCommands)
329
- gitcmd = exec .CommandContext (ctx , gitBinVerb , repoPath )
330
+ command = exec .CommandContext (ctx , gitBinVerb , repoPath )
330
331
}
331
332
332
- process .SetSysProcAttribute (gitcmd )
333
- gitcmd .Dir = setting .RepoRootPath
334
- gitcmd .Stdout = os .Stdout
335
- gitcmd .Stdin = os .Stdin
336
- gitcmd .Stderr = os .Stderr
337
- gitcmd .Env = append (gitcmd .Env , os .Environ ()... )
338
- gitcmd .Env = append (gitcmd .Env ,
333
+ process .SetSysProcAttribute (command )
334
+ command .Dir = setting .RepoRootPath
335
+ command .Stdout = os .Stdout
336
+ command .Stdin = os .Stdin
337
+ command .Stderr = os .Stderr
338
+ command .Env = append (command .Env , os .Environ ()... )
339
+ command .Env = append (command .Env ,
339
340
repo_module .EnvRepoIsWiki + "=" + strconv .FormatBool (results .IsWiki ),
340
341
repo_module .EnvRepoName + "=" + results .RepoName ,
341
342
repo_module .EnvRepoUsername + "=" + results .OwnerName ,
@@ -350,9 +351,9 @@ func runServ(ctx context.Context, c *cli.Command) error {
350
351
)
351
352
// to avoid breaking, here only use the minimal environment variables for the "gitea serv" command.
352
353
// it could be re-considered whether to use the same git.CommonGitCmdEnvs() as "git" command later.
353
- gitcmd .Env = append (gitcmd .Env , git .CommonCmdServEnvs ()... )
354
+ command .Env = append (command .Env , gitcmd .CommonCmdServEnvs ()... )
354
355
355
- if err = gitcmd .Run (); err != nil {
356
+ if err = command .Run (); err != nil {
356
357
return fail (ctx , "Failed to execute git command" , "Failed to execute git command: %v" , err )
357
358
}
358
359
0 commit comments