mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 17:48:00 +01:00
Make gitea serv
respect git binary home (#23138)
Close #23137 The old code is too old (8-9 years ago) Let's try to execute the git commands from git bin home directly. The verb has been checked above, it could only be: * git-upload-pack * git-upload-archive * git-receive-pack * git-lfs-authenticate
This commit is contained in:
parent
443dcc2db0
commit
f5987c24e2
25
cmd/serv.go
25
cmd/serv.go
@ -11,6 +11,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -290,17 +291,21 @@ func runServ(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special handle for Windows.
|
|
||||||
if setting.IsWindows {
|
|
||||||
verb = strings.Replace(verb, "-", " ", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var gitcmd *exec.Cmd
|
var gitcmd *exec.Cmd
|
||||||
verbs := strings.Split(verb, " ")
|
gitBinPath := filepath.Dir(git.GitExecutable) // e.g. /usr/bin
|
||||||
if len(verbs) == 2 {
|
gitBinVerb := filepath.Join(gitBinPath, verb) // e.g. /usr/bin/git-upload-pack
|
||||||
gitcmd = exec.CommandContext(ctx, verbs[0], verbs[1], repoPath)
|
if _, err := os.Stat(gitBinVerb); err != nil {
|
||||||
} else {
|
// if the command "git-upload-pack" doesn't exist, try to split "git-upload-pack" to use the sub-command with git
|
||||||
gitcmd = exec.CommandContext(ctx, verb, repoPath)
|
// ps: Windows only has "git.exe" in the bin path, so Windows always uses this way
|
||||||
|
verbFields := strings.SplitN(verb, "-", 2)
|
||||||
|
if len(verbFields) == 2 {
|
||||||
|
// use git binary with the sub-command part: "C:\...\bin\git.exe", "upload-pack", ...
|
||||||
|
gitcmd = exec.CommandContext(ctx, git.GitExecutable, verbFields[1], repoPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gitcmd == nil {
|
||||||
|
// by default, use the verb (it has been checked above by allowedCommands)
|
||||||
|
gitcmd = exec.CommandContext(ctx, gitBinVerb, repoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
process.SetSysProcAttribute(gitcmd)
|
process.SetSysProcAttribute(gitcmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user