@@ -33,16 +33,18 @@ var (
33
33
// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
34
34
DefaultContext context.Context
35
35
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
38
38
39
- gitVersion * version.Version
39
+ SupportProcReceive bool // >= 2.29
40
+ SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
41
+ }
40
42
)
41
43
42
44
// loadGitVersion tries to get the current git version and stores it into a global variable
43
45
func loadGitVersion () error {
44
46
// doesn't need RWMutex because it's executed by Init()
45
- if gitVersion != nil {
47
+ if DefaultFeatures . GitVersion != nil {
46
48
return nil
47
49
}
48
50
@@ -53,7 +55,7 @@ func loadGitVersion() error {
53
55
54
56
ver , err := parseGitVersionLine (strings .TrimSpace (stdout ))
55
57
if err == nil {
56
- gitVersion = ver
58
+ DefaultFeatures . GitVersion = ver
57
59
}
58
60
return err
59
61
}
@@ -93,7 +95,7 @@ func SetExecutablePath(path string) error {
93
95
return err
94
96
}
95
97
96
- if gitVersion .LessThan (versionRequired ) {
98
+ if DefaultFeatures . GitVersion .LessThan (versionRequired ) {
97
99
moreHint := "get git: https://git-scm.com/download/"
98
100
if runtime .GOOS == "linux" {
99
101
// 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 {
102
104
moreHint = "get git: https://git-scm.com/download/linux and https://ius.io"
103
105
}
104
106
}
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 )
106
108
}
107
109
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 )
110
112
}
111
113
return nil
112
114
}
113
115
114
116
// VersionInfo returns git version information
115
117
func VersionInfo () string {
116
- if gitVersion == nil {
118
+ if DefaultFeatures . GitVersion == nil {
117
119
return "(git not found)"
118
120
}
119
121
format := "%s"
120
- args := []any {gitVersion .Original ()}
122
+ args := []any {DefaultFeatures . GitVersion .Original ()}
121
123
// Since git wire protocol has been released from git v2.18
122
124
if setting .Git .EnableAutoGitWireProtocol && CheckGitVersionAtLeast ("2.18" ) == nil {
123
125
format += ", Wire Protocol %s Enabled"
@@ -187,9 +189,9 @@ func InitFull(ctx context.Context) (err error) {
187
189
if CheckGitVersionAtLeast ("2.9" ) == nil {
188
190
globalCommandArgs = append (globalCommandArgs , "-c" , "credential.helper=" )
189
191
}
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 {
193
195
SupportedObjectFormats = append (SupportedObjectFormats , Sha256ObjectFormat )
194
196
} else {
195
197
log .Warn ("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported" )
@@ -254,7 +256,7 @@ func syncGitConfig() (err error) {
254
256
}
255
257
}
256
258
257
- if SupportProcReceive {
259
+ if DefaultFeatures . SupportProcReceive {
258
260
// set support for AGit flow
259
261
if err := configAddNonExist ("receive.procReceiveRefs" , "refs/for" ); err != nil {
260
262
return err
@@ -309,15 +311,15 @@ func syncGitConfig() (err error) {
309
311
310
312
// CheckGitVersionAtLeast check git version is at least the constraint version
311
313
func CheckGitVersionAtLeast (atLeast string ) error {
312
- if gitVersion == nil {
314
+ if DefaultFeatures . GitVersion == nil {
313
315
panic ("git module is not initialized" ) // it shouldn't happen
314
316
}
315
317
atLeastVersion , err := version .NewVersion (atLeast )
316
318
if err != nil {
317
319
return err
318
320
}
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 )
321
323
}
322
324
return nil
323
325
}
0 commit comments