summaryrefslogtreecommitdiffstats
path: root/modules/git/git.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-06-26 13:28:55 +0200
committerGitHub <noreply@github.com>2021-06-26 13:28:55 +0200
commite3c626834b34fae7728ee7869ed73ee4d1b26a26 (patch)
treeec61ea5376286a78622b95b7d849e8a299c85a28 /modules/git/git.go
parentFixed issues not updated by commits (#16254) (diff)
downloadforgejo-e3c626834b34fae7728ee7869ed73ee4d1b26a26.tar.xz
forgejo-e3c626834b34fae7728ee7869ed73ee4d1b26a26.zip
Let package git depend on setting but not opposite (#15241)
* Let package git depend on setting but not opposite * private some package variables
Diffstat (limited to 'modules/git/git.go')
-rw-r--r--modules/git/git.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/git/git.go b/modules/git/git.go
index ce1b15c953..ef6ec0c2bf 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/modules/process"
+ "code.gitea.io/gitea/modules/setting"
"github.com/hashicorp/go-version"
)
@@ -106,10 +107,42 @@ func SetExecutablePath(path string) error {
return nil
}
+// VersionInfo returns git version information
+func VersionInfo() string {
+ var format = "Git Version: %s"
+ var args = []interface{}{gitVersion.Original()}
+ // Since git wire protocol has been released from git v2.18
+ if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
+ format += ", Wire Protocol %s Enabled"
+ args = append(args, "Version 2") // for focus color
+ }
+
+ return fmt.Sprintf(format, args...)
+}
+
// Init initializes git module
func Init(ctx context.Context) error {
DefaultContext = ctx
+ defaultCommandExecutionTimeout = time.Duration(setting.Git.Timeout.Default) * time.Second
+
+ if err := SetExecutablePath(setting.Git.Path); err != nil {
+ return err
+ }
+
+ // force cleanup args
+ GlobalCommandArgs = []string{}
+
+ if CheckGitVersionAtLeast("2.9") == nil {
+ // Explicitly disable credential helper, otherwise Git credentials might leak
+ GlobalCommandArgs = append(GlobalCommandArgs, "-c", "credential.helper=")
+ }
+
+ // Since git wire protocol has been released from git v2.18
+ if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
+ GlobalCommandArgs = append(GlobalCommandArgs, "-c", "protocol.version=2")
+ }
+
// Save current git version on init to gitVersion otherwise it would require an RWMutex
if err := LoadGitVersion(); err != nil {
return err