File tree 4 files changed +18
-4
lines changed
docs/content/doc/advanced
4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -670,6 +670,8 @@ SCHEDULE = @every 24h
670
670
UPDATE_EXISTING = true
671
671
672
672
[git]
673
+ ; The path of git executable. If empty, Gitea searches through the PATH environment.
674
+ PATH =
673
675
; Disables highlight of added and removed changes
674
676
DISABLE_DIFF_HIGHLIGHT = false
675
677
; Max number of lines allowed in a single file in diff view
Original file line number Diff line number Diff line change @@ -409,6 +409,7 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false`
409
409
410
410
## Git (` git ` )
411
411
412
+ - ` PATH ` : ** ""** : The path of git executable. If empty, Gitea searches through the PATH environment.
412
413
- ` MAX_GIT_DIFF_LINES ` : ** 100** : Max number of lines allowed of a single file in diff view.
413
414
- ` MAX_GIT_DIFF_LINE_CHARACTERS ` : ** 5000** : Max character count per line highlighted in diff view.
414
415
- ` MAX_GIT_DIFF_FILES ` : ** 100** : Max number of files shown in diff view.
Original file line number Diff line number Diff line change @@ -77,20 +77,27 @@ func BinVersion() (string, error) {
77
77
return gitVersion , nil
78
78
}
79
79
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
+ }
81
86
absPath , err := exec .LookPath (GitExecutable )
82
87
if err != nil {
83
- panic ( fmt .Sprintf ("Git not found: %v" , err ) )
88
+ return fmt .Errorf ("Git not found: %v" , err )
84
89
}
85
90
GitExecutable = absPath
86
91
87
92
gitVersion , err := BinVersion ()
88
93
if err != nil {
89
- panic ( fmt .Sprintf ("Git version missing: %v" , err ) )
94
+ return fmt .Errorf ("Git version missing: %v" , err )
90
95
}
91
96
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 )
93
98
}
99
+
100
+ return nil
94
101
}
95
102
96
103
// Init initializes git module
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
var (
17
17
// Git settings
18
18
Git = struct {
19
+ Path string
19
20
DisableDiffHighlight bool
20
21
MaxGitDiffLines int
21
22
MaxGitDiffLineCharacters int
@@ -59,6 +60,9 @@ func newGit() {
59
60
if err := Cfg .Section ("git" ).MapTo (& Git ); err != nil {
60
61
log .Fatal ("Failed to map Git settings: %v" , err )
61
62
}
63
+ if err := git .SetExecutablePath (Git .Path ); err != nil {
64
+ log .Fatal ("Failed to initialize Git settings" , err )
65
+ }
62
66
git .DefaultCommandExecutionTimeout = time .Duration (Git .Timeout .Default ) * time .Second
63
67
64
68
binVersion , err := git .BinVersion ()
You can’t perform that action at this time.
0 commit comments