Skip to content

Commit f88aa1d

Browse files
typelesstechknowlogick
authored andcommitted
Support git.PATH entry in app.ini (#6772)
1 parent 8d9d6aa commit f88aa1d

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

custom/conf/app.ini.sample

+2
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ SCHEDULE = @every 24h
670670
UPDATE_EXISTING = true
671671

672672
[git]
673+
; The path of git executable. If empty, Gitea searches through the PATH environment.
674+
PATH =
673675
; Disables highlight of added and removed changes
674676
DISABLE_DIFF_HIGHLIGHT = false
675677
; Max number of lines allowed in a single file in diff view

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false`
409409

410410
## Git (`git`)
411411

412+
- `PATH`: **""**: The path of git executable. If empty, Gitea searches through the PATH environment.
412413
- `MAX_GIT_DIFF_LINES`: **100**: Max number of lines allowed of a single file in diff view.
413414
- `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view.
414415
- `MAX_GIT_DIFF_FILES`: **100**: Max number of files shown in diff view.

modules/git/git.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,27 @@ func BinVersion() (string, error) {
7777
return gitVersion, nil
7878
}
7979

80-
func init() {
80+
// SetExecutablePath changes the path of git executable and checks the file permission and version.
81+
func SetExecutablePath(path string) error {
82+
// If path is empty, we use the default value of GitExecutable "git" to search for the location of git.
83+
if path != "" {
84+
GitExecutable = path
85+
}
8186
absPath, err := exec.LookPath(GitExecutable)
8287
if err != nil {
83-
panic(fmt.Sprintf("Git not found: %v", err))
88+
return fmt.Errorf("Git not found: %v", err)
8489
}
8590
GitExecutable = absPath
8691

8792
gitVersion, err := BinVersion()
8893
if err != nil {
89-
panic(fmt.Sprintf("Git version missing: %v", err))
94+
return fmt.Errorf("Git version missing: %v", err)
9095
}
9196
if version.Compare(gitVersion, GitVersionRequired, "<") {
92-
panic(fmt.Sprintf("Git version not supported. Requires version > %v", GitVersionRequired))
97+
return fmt.Errorf("Git version not supported. Requires version > %v", GitVersionRequired)
9398
}
99+
100+
return nil
94101
}
95102

96103
// Init initializes git module

modules/setting/git.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
var (
1717
// Git settings
1818
Git = struct {
19+
Path string
1920
DisableDiffHighlight bool
2021
MaxGitDiffLines int
2122
MaxGitDiffLineCharacters int
@@ -59,6 +60,9 @@ func newGit() {
5960
if err := Cfg.Section("git").MapTo(&Git); err != nil {
6061
log.Fatal("Failed to map Git settings: %v", err)
6162
}
63+
if err := git.SetExecutablePath(Git.Path); err != nil {
64+
log.Fatal("Failed to initialize Git settings", err)
65+
}
6266
git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
6367

6468
binVersion, err := git.BinVersion()

0 commit comments

Comments
 (0)