35
35
GlobalConfigFile string
36
36
37
37
// DefaultContext is the default context to run git commands in
38
- // will be overwritten by Init with HammerContext
38
+ // will be overwritten by InitWithConfigSync with HammerContext
39
39
DefaultContext = context .Background ()
40
40
41
41
// SupportProcReceive version >= 2.29.0
@@ -129,8 +129,9 @@ func VersionInfo() string {
129
129
return fmt .Sprintf (format , args ... )
130
130
}
131
131
132
- // Init initializes git module
133
- func Init (ctx context.Context ) error {
132
+ // InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
133
+ // This method doesn't change anything to filesystem
134
+ func InitSimple (ctx context.Context ) error {
134
135
DefaultContext = ctx
135
136
136
137
if setting .Git .Timeout .Default > 0 {
@@ -141,9 +142,6 @@ func Init(ctx context.Context) error {
141
142
return errors .New ("RepoRootPath is empty, git module needs that setting before initialization" )
142
143
}
143
144
144
- if err := os .MkdirAll (setting .RepoRootPath , os .ModePerm ); err != nil {
145
- return fmt .Errorf ("unable to create directory %s, err:%w" , setting .RepoRootPath , err )
146
- }
147
145
GlobalConfigFile = setting .RepoRootPath + "/gitconfig"
148
146
149
147
if err := SetExecutablePath (setting .Git .Path ); err != nil {
@@ -153,6 +151,20 @@ func Init(ctx context.Context) error {
153
151
// force cleanup args
154
152
globalCommandArgs = []string {}
155
153
154
+ return nil
155
+ }
156
+
157
+ // InitWithConfigSync initializes git module. This method may create directories or write files into filesystem
158
+ func InitWithConfigSync (ctx context.Context ) error {
159
+ err := InitSimple (ctx )
160
+ if err != nil {
161
+ return err
162
+ }
163
+
164
+ if err = os .MkdirAll (setting .RepoRootPath , os .ModePerm ); err != nil {
165
+ return fmt .Errorf ("unable to create directory %s, err:%w" , setting .RepoRootPath , err )
166
+ }
167
+
156
168
if CheckGitVersionAtLeast ("2.9" ) == nil {
157
169
// Explicitly disable credential helper, otherwise Git credentials might leak
158
170
globalCommandArgs = append (globalCommandArgs , "-c" , "credential.helper=" )
@@ -223,13 +235,11 @@ func Init(ctx context.Context) error {
223
235
if err := configSet ("core.longpaths" , "true" ); err != nil {
224
236
return err
225
237
}
226
- }
227
- if setting .Git .DisableCoreProtectNTFS {
228
- if err := configSet ("core.protectntfs" , "false" ); err != nil {
229
- return err
238
+ if setting .Git .DisableCoreProtectNTFS {
239
+ globalCommandArgs = append (globalCommandArgs , "-c" , "core.protectntfs=false" )
230
240
}
231
- globalCommandArgs = append (globalCommandArgs , "-c" , "core.protectntfs=false" )
232
241
}
242
+
233
243
return nil
234
244
}
235
245
0 commit comments