mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-12 00:34:20 -04:00
Pre-calculate the absolute path of git (#6575)
* Pre-caculate the absolute path of git * Do not repeat string literals which has been defined somewhere Also make it flexible to accept customized/user-defined value.
This commit is contained in:
parent
7a4c29c739
commit
2a9806bfc6
@ -41,7 +41,7 @@ func NewCommand(args ...string) *Command {
|
|||||||
cargs := make([]string, len(GlobalCommandArgs))
|
cargs := make([]string, len(GlobalCommandArgs))
|
||||||
copy(cargs, GlobalCommandArgs)
|
copy(cargs, GlobalCommandArgs)
|
||||||
return &Command{
|
return &Command{
|
||||||
name: "git",
|
name: GitExecutable,
|
||||||
args: append(cargs, args...),
|
args: append(cargs, args...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -26,6 +27,10 @@ var (
|
|||||||
Prefix = "[git-module] "
|
Prefix = "[git-module] "
|
||||||
// GitVersionRequired is the minimum Git version required
|
// GitVersionRequired is the minimum Git version required
|
||||||
GitVersionRequired = "1.7.2"
|
GitVersionRequired = "1.7.2"
|
||||||
|
|
||||||
|
// GitExecutable is the command name of git
|
||||||
|
// Could be updated to an absolute path while initialization
|
||||||
|
GitExecutable = "git"
|
||||||
)
|
)
|
||||||
|
|
||||||
func log(format string, args ...interface{}) {
|
func log(format string, args ...interface{}) {
|
||||||
@ -71,6 +76,12 @@ func BinVersion() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
absPath, err := exec.LookPath(GitExecutable)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Git not found: %v", err))
|
||||||
|
}
|
||||||
|
GitExecutable = absPath
|
||||||
|
|
||||||
gitVersion, err := BinVersion()
|
gitVersion, err := BinVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Git version missing: %v", err))
|
panic(fmt.Sprintf("Git version missing: %v", err))
|
||||||
|
Loading…
Reference in New Issue
Block a user