summaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2019-07-07 15:26:56 +0800
committertechknowlogick <techknowlogick@gitea.io>2019-07-07 03:26:56 -0400
commitf88aa1d21572beafc5a22db0c9712751f47fc0ac (patch)
treeabeb23e8a3b141e5156f7ec99222e968c8d5a73d /modules/git
parent8d9d6aa903baf3662fa31bceb489291564a873d1 (diff)
downloadgitea-f88aa1d21572beafc5a22db0c9712751f47fc0ac.tar.gz
gitea-f88aa1d21572beafc5a22db0c9712751f47fc0ac.zip
Support git.PATH entry in app.ini (#6772)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/git.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/modules/git/git.go b/modules/git/git.go
index fda6f45251..964760dfda 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -77,20 +77,27 @@ func BinVersion() (string, error) {
return gitVersion, nil
}
-func init() {
+// SetExecutablePath changes the path of git executable and checks the file permission and version.
+func SetExecutablePath(path string) error {
+ // If path is empty, we use the default value of GitExecutable "git" to search for the location of git.
+ if path != "" {
+ GitExecutable = path
+ }
absPath, err := exec.LookPath(GitExecutable)
if err != nil {
- panic(fmt.Sprintf("Git not found: %v", err))
+ return fmt.Errorf("Git not found: %v", err)
}
GitExecutable = absPath
gitVersion, err := BinVersion()
if err != nil {
- panic(fmt.Sprintf("Git version missing: %v", err))
+ return fmt.Errorf("Git version missing: %v", err)
}
if version.Compare(gitVersion, GitVersionRequired, "<") {
- panic(fmt.Sprintf("Git version not supported. Requires version > %v", GitVersionRequired))
+ return fmt.Errorf("Git version not supported. Requires version > %v", GitVersionRequired)
}
+
+ return nil
}
// Init initializes git module