From 7926304996d60bec631f43eb7f082a7005947267 Mon Sep 17 00:00:00 2001 From: Mura Li Date: Thu, 11 Apr 2019 10:38:48 +0800 Subject: [PATCH 1/2] Pre-caculate the absolute path of git --- modules/git/command.go | 2 +- modules/git/git.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/git/command.go b/modules/git/command.go index d354635119b21..3602717702f1b 100644 --- a/modules/git/command.go +++ b/modules/git/command.go @@ -41,7 +41,7 @@ func NewCommand(args ...string) *Command { cargs := make([]string, len(GlobalCommandArgs)) copy(cargs, GlobalCommandArgs) return &Command{ - name: "git", + name: GitExecutable, args: append(cargs, args...), } } diff --git a/modules/git/git.go b/modules/git/git.go index 150b80fb076b8..011acc15eed44 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -7,6 +7,7 @@ package git import ( "fmt" + "os/exec" "strings" "time" @@ -26,6 +27,10 @@ var ( Prefix = "[git-module] " // GitVersionRequired is the minimum Git version required 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{}) { @@ -71,6 +76,12 @@ func BinVersion() (string, error) { } func init() { + absPath, err := exec.LookPath("git") + if err != nil { + panic(fmt.Sprintf("Git not found: %v", err)) + } + GitExecutable = absPath + gitVersion, err := BinVersion() if err != nil { panic(fmt.Sprintf("Git version missing: %v", err)) From 62b38224462754638d5d57de5a78242a8d8af731 Mon Sep 17 00:00:00 2001 From: Mura Li Date: Wed, 17 Apr 2019 17:28:04 +0800 Subject: [PATCH 2/2] Do not repeat string literals which has been defined somewhere Also make it flexible to accept customized/user-defined value. --- modules/git/git.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/git.go b/modules/git/git.go index 011acc15eed44..abae0423c2c5a 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -76,7 +76,7 @@ func BinVersion() (string, error) { } func init() { - absPath, err := exec.LookPath("git") + absPath, err := exec.LookPath(GitExecutable) if err != nil { panic(fmt.Sprintf("Git not found: %v", err)) }