Skip to content

Commit 2a9806b

Browse files
typelesslafriks
authored andcommitted
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.
1 parent 7a4c29c commit 2a9806b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

modules/git/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewCommand(args ...string) *Command {
4141
cargs := make([]string, len(GlobalCommandArgs))
4242
copy(cargs, GlobalCommandArgs)
4343
return &Command{
44-
name: "git",
44+
name: GitExecutable,
4545
args: append(cargs, args...),
4646
}
4747
}

modules/git/git.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package git
77

88
import (
99
"fmt"
10+
"os/exec"
1011
"strings"
1112
"time"
1213

@@ -26,6 +27,10 @@ var (
2627
Prefix = "[git-module] "
2728
// GitVersionRequired is the minimum Git version required
2829
GitVersionRequired = "1.7.2"
30+
31+
// GitExecutable is the command name of git
32+
// Could be updated to an absolute path while initialization
33+
GitExecutable = "git"
2934
)
3035

3136
func log(format string, args ...interface{}) {
@@ -71,6 +76,12 @@ func BinVersion() (string, error) {
7176
}
7277

7378
func init() {
79+
absPath, err := exec.LookPath(GitExecutable)
80+
if err != nil {
81+
panic(fmt.Sprintf("Git not found: %v", err))
82+
}
83+
GitExecutable = absPath
84+
7485
gitVersion, err := BinVersion()
7586
if err != nil {
7687
panic(fmt.Sprintf("Git version missing: %v", err))

0 commit comments

Comments
 (0)