mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Let package git depend on setting but not opposite (#15241)
* Let package git depend on setting but not opposite * private some package variables
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user