aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2019-04-17 19:11:37 +0800
committerLauris BH <lauris@nix.lv>2019-04-17 14:11:37 +0300
commit2a9806bfc64c2b9fe2027fb6b7bd1844c0cac365 (patch)
tree6787b1f8f64c4eb247a6fd591b9b3b29507e0da4 /modules
parent7a4c29c739fa9b08f901220ebcb2948daf491692 (diff)
downloadgitea-2a9806bfc64c2b9fe2027fb6b7bd1844c0cac365.tar.gz
gitea-2a9806bfc64c2b9fe2027fb6b7bd1844c0cac365.zip
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.
Diffstat (limited to 'modules')
-rw-r--r--modules/git/command.go2
-rw-r--r--modules/git/git.go11
2 files changed, 12 insertions, 1 deletions
diff --git a/modules/git/command.go b/modules/git/command.go
index d354635119..3602717702 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 150b80fb07..abae0423c2 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(GitExecutable)
+ 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))