aboutsummaryrefslogtreecommitdiffstats
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
parent8d9d6aa903baf3662fa31bceb489291564a873d1 (diff)
downloadgitea-f88aa1d21572beafc5a22db0c9712751f47fc0ac.tar.gz
gitea-f88aa1d21572beafc5a22db0c9712751f47fc0ac.zip
Support git.PATH entry in app.ini (#6772)
-rw-r--r--custom/conf/app.ini.sample2
-rw-r--r--docs/content/doc/advanced/config-cheat-sheet.en-us.md1
-rw-r--r--modules/git/git.go15
-rw-r--r--modules/setting/git.go4
4 files changed, 18 insertions, 4 deletions
diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample
index 89c12c42bf..e44cc90a4b 100644
--- a/custom/conf/app.ini.sample
+++ b/custom/conf/app.ini.sample
@@ -670,6 +670,8 @@ SCHEDULE = @every 24h
UPDATE_EXISTING = true
[git]
+; The path of git executable. If empty, Gitea searches through the PATH environment.
+PATH =
; Disables highlight of added and removed changes
DISABLE_DIFF_HIGHLIGHT = false
; Max number of lines allowed in a single file in diff view
diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md
index 128e01b90a..61905f8ad8 100644
--- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md
+++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md
@@ -409,6 +409,7 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false`
## Git (`git`)
+- `PATH`: **""**: The path of git executable. If empty, Gitea searches through the PATH environment.
- `MAX_GIT_DIFF_LINES`: **100**: Max number of lines allowed of a single file in diff view.
- `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view.
- `MAX_GIT_DIFF_FILES`: **100**: Max number of files shown in diff view.
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
diff --git a/modules/setting/git.go b/modules/setting/git.go
index 4163f1039d..8495be8836 100644
--- a/modules/setting/git.go
+++ b/modules/setting/git.go
@@ -16,6 +16,7 @@ import (
var (
// Git settings
Git = struct {
+ Path string
DisableDiffHighlight bool
MaxGitDiffLines int
MaxGitDiffLineCharacters int
@@ -59,6 +60,9 @@ func newGit() {
if err := Cfg.Section("git").MapTo(&Git); err != nil {
log.Fatal("Failed to map Git settings: %v", err)
}
+ if err := git.SetExecutablePath(Git.Path); err != nil {
+ log.Fatal("Failed to initialize Git settings", err)
+ }
git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
binVersion, err := git.BinVersion()