Skip to content

Commit

Permalink
ci_runner: conditionally set extension.partialClone based on filter
Browse files Browse the repository at this point in the history
If the filter is empty, unset the config.
If the filter is available, set the config to "origin" to indicate the
remote is a promisor remote.

https://github.com/git/git/blob/08bdfd453584e489d5a551aecbdcb77584e1b958/Documentation/config/extensions.adoc?plain=1#L37-L47
  • Loading branch information
sluongng committed Feb 28, 2025
1 parent 6c246d4 commit 3f8405f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions enterprise/server/cmd/ci_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1963,10 +1963,6 @@ func (ws *workspace) config(ctx context.Context) error {
{"user.email", "[email protected]"},
{"user.name", "BuildBuddy"},
{"advice.detachedHead", "false"},
// With the version of git that we have installed in the CI runner
// image, --filter=blob:none requires the partialClone extension to be
// enabled.
{"extensions.partialClone", "true"},
// Disable this check for `git fetch` performance improvements
{"fetch.showForcedUpdates", "false"},
// Disable automatic gc - it can interfere with running `rm -rf .git` in
Expand All @@ -1981,6 +1977,23 @@ func (ws *workspace) config(ctx context.Context) error {
// displays a blocking popup dialog)
cfg = append(cfg, []string{"credential.helper", ""})
}
if len(*gitFetchFilters) > 0 {
// With the version of git that we have installed in the CI runner
// image, --filter=blob:none requires the partialClone extension to be
// enabled.
cfg = append(cfg, []string{"extensions.partialClone", "origin"})
} else {
// TODO(sluongng): "--enset-all" is deprecated in newer versions of git.
// Switch to "git config unset --all" when we upgrade the git version.
if _, err := git(ctx, io.Discard, "config", "--unset-all", "extensions.partialClone"); err != nil {
// Expect code 5 when config was not set.
// From git-config(1) man page:
// "you try to unset an option which does not exist (ret=5),"
if err.Error() != "exit status 5" {
return fmt.Errorf("faild to unset git config extensions.partialClone: %w", err)
}
}
}

writeCommandSummary(ws.log, "Configuring repository...")
for _, kv := range cfg {
Expand Down

0 comments on commit 3f8405f

Please sign in to comment.