sync: add repo.smartsyncdefault checkout policy

Workspace managers that provision repo checkouts need a way to make
Smart Sync the default for branches that define a manifest server,
without silently falling back to ToT on Smart Sync failures (where
unapproved or broken ToT trees defeat the point of Smart Sync).

Previously, setting repo.smartsync=true on init had two drawbacks:
it overrode per-user sync.smartsync=false and manifest-level opt-outs,
and default Smart Sync failures still fell back silently to ToT.
Removing <manifest-server> from a branch manifest to opt out also broke
explicit -s/-t syncs.

With repo.smartsyncdefault=explicit configured on a checkout:

- Plain repo sync enables Smart Sync whenever the manifest defines
  <manifest-server>, unless overridden by CLI flags, repo.smartsync,
  sync.smartsync, or <default sync-smartsync="false"/>.
- Default-enabled Smart Sync failures abort the sync instead of
  falling back to ToT, and print a hint pointing users to
  --no-smart-sync (or --head) to bypass Smart Sync for that sync.
- Branches without <manifest-server> or with
  <default sync-smartsync="false"/> sync ToT by default while keeping
  explicit -s/-t functional.

Bug: 543101585
Bug: 568962967
Test: pytest tests/test_manifest_xml.py tests/test_project.py
Test: pytest tests/test_subcmds_sync.py tests/e2e/test_init_sync.py
Change-Id: I5de45544df84366592978dd81c01e10dae964a1e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/658243
Tested-by: Rahul Yadav <yadavrah@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Rahul Yadav <yadavrah@google.com>
This commit is contained in:
Rahul Yadav authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-11-23 11:08:55 -08:00
1 parent 344ec87370
commit affca0d4ab
11 files changed
+385 -28

No files matched your search

+1
View File
@@ -181,6 +181,7 @@ User controlled settings are initialized when running `repo init`.
| repo.partialcloneexclude | `--partial-clone-exclude` | Comma-delimited list of project names (not paths) to exclude while using [partial git clones] |
| repo.reference | `--reference` | Reference repo client checkout |
| repo.smartsync | `--smart-sync` | Default to [Smart Sync](./smart-sync.md) when syncing |
| repo.smartsyncdefault | (internal) | Fallback [Smart Sync](./smart-sync.md) policy; `explicit` enables Smart Sync when `<manifest-server>` is set (below CLI, `repo.smartsync`, `sync.smartsync`, and `sync-smartsync`) and treats default Smart Syncs as explicit |
| repo.\<branch\>.smartsyncbranch | `--smart-sync-branch` | Server branch to query when [Smart Sync](./smart-sync.md)ing `<branch>` |
| repo.submodules | `--submodules` | Sync git submodules |
| repo.superproject | `--use-superproject` | Sync [superproject] |
+3 -1
View File
@@ -242,7 +242,9 @@ will use this value if specified; otherwise projects default to
false when depth is set on a non-mirror checkout, and true
otherwise.
Attribute `sync-smartsync`: Set to true to enable smart sync by default.
Attribute `sync-smartsync`: Set to true to enable smart sync by default,
or set to false to disable default smart sync for the manifest (explicit
`-s`/`-t` invocations still work when `<manifest-server>` is defined).
### Element manifest-server
+5
View File
@@ -245,6 +245,11 @@ explicit target or manifest source (such as `-t`/`--smart-tag`,
`-m`/`--manifest-name` or `--superproject-revision`) will also disable the
default Smart Sync behavior.
Setting `sync-smartsync="false"` explicitly opts the manifest out of default
Smart Sync (for example, overriding a checkout fallback policy) while keeping
`<manifest-server>` available for explicit `-s`/`--smart-sync` and
`-t`/`--smart-tag` invocations.
Users can override this manifest default on their workstation with the
`sync.smartsync` user setting; see
[Per-user default](#Per_user-default-sync_smartsync) below.