Skip to content

Commit a3575c7

Browse files
author
Mura Li
committed
Add Git.Path for app.ini
1 parent 75d4414 commit a3575c7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/git/git.go

Lines changed: 11 additions & 4 deletions
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+
// SetExeutablecPath 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

Lines changed: 4 additions & 0 deletions
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)