From a3575c798fda5cab0b3d2410adcaea7b3827339b Mon Sep 17 00:00:00 2001 From: Mura Li Date: Sat, 27 Apr 2019 09:15:30 +0800 Subject: [PATCH 1/5] Add Git.Path for app.ini --- modules/git/git.go | 15 +++++++++++---- modules/setting/git.go | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/git/git.go b/modules/git/git.go index fda6f4525195d..2e00830bd8463 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -77,20 +77,27 @@ func BinVersion() (string, error) { return gitVersion, nil } -func init() { +// SetExeutablecPath 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 4163f1039d4ee..8495be8836f13 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() From 71c5c1f03aa5b12af159d78eeb7bfe6e903aee03 Mon Sep 17 00:00:00 2001 From: Mura Li Date: Sat, 27 Apr 2019 09:46:00 +0800 Subject: [PATCH 2/5] Add documentation in app.ini.sample --- custom/conf/app.ini.sample | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index a674984a2584e..be26106947e04 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -668,6 +668,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 From 81f82d3ddef0dd0ae1c11a0e0273c5a513f6acb2 Mon Sep 17 00:00:00 2001 From: Mura Li Date: Sat, 27 Apr 2019 09:48:44 +0800 Subject: [PATCH 3/5] Fix typo --- 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 2e00830bd8463..964760dfda79b 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -77,7 +77,7 @@ func BinVersion() (string, error) { return gitVersion, nil } -// SetExeutablecPath changes the path of git executable and checks the file permission and version. +// 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 != "" { From fa9672eacbbde988dc35756d5056612fc404261f Mon Sep 17 00:00:00 2001 From: Mura Li Date: Sat, 27 Apr 2019 10:09:12 +0800 Subject: [PATCH 4/5] Update config-cheat-sheet.en-us.md --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + 1 file changed, 1 insertion(+) 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 11dbfc5d095ec..ae7662137b5b6 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -408,6 +408,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. From fc591d5a00976765c0ac3d4cc5c7e039e5549b6f Mon Sep 17 00:00:00 2001 From: Mura Li Date: Sat, 27 Apr 2019 10:11:18 +0800 Subject: [PATCH 5/5] Follow the formatting convention --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ae7662137b5b6..1fe671d2dc4ec 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -408,7 +408,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. +- `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.