@@ -33,16 +33,18 @@ var (
3333 // DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
3434 DefaultContext context.Context
3535
36- SupportProcReceive bool // >= 2.29
37- SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
36+ DefaultFeatures struct {
37+ GitVersion * version. Version
3838
39- gitVersion * version.Version
39+ SupportProcReceive bool // >= 2.29
40+ SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
41+ }
4042)
4143
4244// loadGitVersion tries to get the current git version and stores it into a global variable
4345func loadGitVersion () error {
4446 // doesn't need RWMutex because it's executed by Init()
45- if gitVersion != nil {
47+ if DefaultFeatures . GitVersion != nil {
4648 return nil
4749 }
4850
@@ -53,7 +55,7 @@ func loadGitVersion() error {
5355
5456 ver , err := parseGitVersionLine (strings .TrimSpace (stdout ))
5557 if err == nil {
56- gitVersion = ver
58+ DefaultFeatures . GitVersion = ver
5759 }
5860 return err
5961}
@@ -93,7 +95,7 @@ func SetExecutablePath(path string) error {
9395 return err
9496 }
9597
96- if gitVersion .LessThan (versionRequired ) {
98+ if DefaultFeatures . GitVersion .LessThan (versionRequired ) {
9799 moreHint := "get git: https://git-scm.com/download/"
98100 if runtime .GOOS == "linux" {
99101 // there are a lot of CentOS/RHEL users using old git, so we add a special hint for them
@@ -102,22 +104,22 @@ func SetExecutablePath(path string) error {
102104 moreHint = "get git: https://git-scm.com/download/linux and https://ius.io"
103105 }
104106 }
105- return fmt .Errorf ("installed git version %q is not supported, Gitea requires git version >= %q, %s" , gitVersion .Original (), RequiredVersion , moreHint )
107+ return fmt .Errorf ("installed git version %q is not supported, Gitea requires git version >= %q, %s" , DefaultFeatures . GitVersion .Original (), RequiredVersion , moreHint )
106108 }
107109
108- if err = checkGitVersionCompatibility (gitVersion ); err != nil {
109- return fmt .Errorf ("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git" , gitVersion .String (), err )
110+ if err = checkGitVersionCompatibility (DefaultFeatures . GitVersion ); err != nil {
111+ return fmt .Errorf ("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git" , DefaultFeatures . GitVersion .String (), err )
110112 }
111113 return nil
112114}
113115
114116// VersionInfo returns git version information
115117func VersionInfo () string {
116- if gitVersion == nil {
118+ if DefaultFeatures . GitVersion == nil {
117119 return "(git not found)"
118120 }
119121 format := "%s"
120- args := []any {gitVersion .Original ()}
122+ args := []any {DefaultFeatures . GitVersion .Original ()}
121123 // Since git wire protocol has been released from git v2.18
122124 if setting .Git .EnableAutoGitWireProtocol && CheckGitVersionAtLeast ("2.18" ) == nil {
123125 format += ", Wire Protocol %s Enabled"
@@ -187,9 +189,9 @@ func InitFull(ctx context.Context) (err error) {
187189 if CheckGitVersionAtLeast ("2.9" ) == nil {
188190 globalCommandArgs = append (globalCommandArgs , "-c" , "credential.helper=" )
189191 }
190- SupportProcReceive = CheckGitVersionAtLeast ("2.29" ) == nil
191- SupportHashSha256 = CheckGitVersionAtLeast ("2.42" ) == nil && ! isGogit
192- if SupportHashSha256 {
192+ DefaultFeatures . SupportProcReceive = CheckGitVersionAtLeast ("2.29" ) == nil
193+ DefaultFeatures . SupportHashSha256 = CheckGitVersionAtLeast ("2.42" ) == nil && ! isGogit
194+ if DefaultFeatures . SupportHashSha256 {
193195 SupportedObjectFormats = append (SupportedObjectFormats , Sha256ObjectFormat )
194196 } else {
195197 log .Warn ("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported" )
@@ -254,7 +256,7 @@ func syncGitConfig() (err error) {
254256 }
255257 }
256258
257- if SupportProcReceive {
259+ if DefaultFeatures . SupportProcReceive {
258260 // set support for AGit flow
259261 if err := configAddNonExist ("receive.procReceiveRefs" , "refs/for" ); err != nil {
260262 return err
@@ -309,15 +311,15 @@ func syncGitConfig() (err error) {
309311
310312// CheckGitVersionAtLeast check git version is at least the constraint version
311313func CheckGitVersionAtLeast (atLeast string ) error {
312- if gitVersion == nil {
314+ if DefaultFeatures . GitVersion == nil {
313315 panic ("git module is not initialized" ) // it shouldn't happen
314316 }
315317 atLeastVersion , err := version .NewVersion (atLeast )
316318 if err != nil {
317319 return err
318320 }
319- if gitVersion .Compare (atLeastVersion ) < 0 {
320- return fmt .Errorf ("installed git binary version %s is not at least %s" , gitVersion .Original (), atLeast )
321+ if DefaultFeatures . GitVersion .Compare (atLeastVersion ) < 0 {
322+ return fmt .Errorf ("installed git binary version %s is not at least %s" , DefaultFeatures . GitVersion .Original (), atLeast )
321323 }
322324 return nil
323325}
0 commit comments