Skip to content

Commit b57e360

Browse files
committed
Set uploadpack.allowFilter etc on gitconfig to enable partial clones with ssh
When setting.Git.DisablePartialClone is set to false then the web server will add filter support to web http. It does this by using `-c` command arguments but this will not work on gitea serv as the upload-pack and receive-pack commands do not support this. Instead we move these options into the .gitconfig instead. Fix #20400 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 6d31814 commit b57e360

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: modules/git/git.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ func InitFull(ctx context.Context) (err error) {
185185
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
186186
}
187187

188-
// By default partial clones are disabled, enable them from git v2.22
189-
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
190-
globalCommandArgs = append(globalCommandArgs, "-c", "uploadpack.allowfilter=true", "-c", "uploadpack.allowAnySHA1InWant=true")
191-
}
192-
193188
// Explicitly disable credential helper, otherwise Git credentials might leak
194189
if CheckGitVersionAtLeast("2.9") == nil {
195190
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
@@ -286,7 +281,20 @@ func syncGitConfig() (err error) {
286281
}
287282
}
288283

289-
return nil
284+
// By default partial clones are disabled, enable them from git v2.22
285+
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
286+
if err = configSet("uploadpack.allowfilter", "true"); err != nil {
287+
return err
288+
}
289+
err = configSet("uploadpack.allowAnySHA1InWant", "true")
290+
} else {
291+
if err = configUnsetAll("uploadpack.allowfilter", "true"); err != nil {
292+
return err
293+
}
294+
err = configUnsetAll("uploadpack.allowAnySHA1InWant", "true")
295+
}
296+
297+
return err
290298
}
291299

292300
// CheckGitVersionAtLeast check git version is at least the constraint version

0 commit comments

Comments
 (0)