Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support git.PATH entry in app.ini #6772

Merged
merged 6 commits into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ SCHEDULE = @every 24h
UPDATE_EXISTING = true

[git]
; The path of git executable. If empty, Gitea searches through the PATH environment.
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
PATH =
; Disables highlight of added and removed changes
DISABLE_DIFF_HIGHLIGHT = false
; Max number of lines allowed in a single file in diff view
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 11 additions & 4 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions modules/setting/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var (
// Git settings
Git = struct {
Path string
DisableDiffHighlight bool
MaxGitDiffLines int
MaxGitDiffLineCharacters int
Expand Down Expand Up @@ -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()
Expand Down