sync: Add --superproject-rev flag to sync to specific revision

Allow syncing the outer manifest to a state defined by a specific
superproject revision. It updates the superproject, reads the manifest
commit from .supermanifest, and checks out the outer manifest project
to that commit.

Submanifests are then processed normally, allowing them to be updated
to the revisions specified in the new outer manifest state.

Bug: 416589884
Change-Id: I304c37a2b8794f9b74cb7e5e209a8a93762bdb52
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/576321
Commit-Queue: Gavin Mak <gavinmak@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Gavin Mak
2026-04-22 00:39:42 +00:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 1b4e7a04be
commit 2d54384a5e
5 changed files with 271 additions and 10 deletions
+78 -7
View File
@@ -64,6 +64,7 @@ from error import SyncError
from error import UpdateManifestError
import event_log
from git_command import git_require
from git_command import GitCommand
from git_config import GetUrlCookieFile
from git_refs import HEAD
from git_refs import R_HEADS
@@ -565,6 +566,11 @@ later is required to fix a server side protocol bug.
dest="use_superproject",
help="disable use of manifest superprojects",
)
p.add_option(
"--superproject-revision",
action="store",
help="sync to superproject revision (applies to outer manifest)",
)
p.add_option("--tags", action="store_true", help="fetch tags")
p.add_option(
"--no-tags",
@@ -668,6 +674,24 @@ later is required to fix a server side protocol bug.
or opt.current_branch_only
)
def _ConfigureSuperproject(
self,
opt: optparse.Values,
manifest,
revision: Optional[str] = None,
) -> bool:
"""Configure superproject with options."""
if not manifest.superproject:
return False
manifest.superproject.SetQuiet(not opt.verbose)
print_messages = git_superproject.PrintMessages(
opt.use_superproject, manifest
)
manifest.superproject.SetPrintMessages(print_messages)
if revision:
manifest.superproject.SetRevisionId(revision)
return print_messages
def _UpdateProjectsRevisionId(
self, opt, args, superproject_logging_data, manifest
):
@@ -741,11 +765,7 @@ later is required to fix a server side protocol bug.
if not use_super:
continue
m.superproject.SetQuiet(not opt.verbose)
print_messages = git_superproject.PrintMessages(
opt.use_superproject, m
)
m.superproject.SetPrintMessages(print_messages)
print_messages = self._ConfigureSuperproject(opt, m)
update_result = m.superproject.UpdateProjectsRevisionId(
per_manifest[m.path_prefix], git_event_log=self.git_event_log
)
@@ -1832,7 +1852,11 @@ later is required to fix a server side protocol bug.
mp: the manifestProject to query.
manifest_name: Manifest file to be reloaded.
"""
if not mp.standalone_manifest_url:
if opt.superproject_revision and mp.manifest == self.outer_manifest:
self._SyncToSuperprojectRev(
opt, mp.manifest, mp, manifest_name, errors
)
elif not mp.standalone_manifest_url:
self._UpdateManifestProject(opt, mp, manifest_name, errors)
if mp.manifest.submanifests:
@@ -2041,6 +2065,53 @@ later is required to fix a server side protocol bug.
if not success:
print("Warning: post-sync hook reported failure.")
def _SyncToSuperprojectRev(
self,
opt: optparse.Values,
manifest,
mp: Project,
manifest_name: Optional[str],
errors: List[Exception],
) -> None:
"""Sync to a specific superproject commit."""
if not manifest.superproject:
raise SyncError("superproject not defined in manifest")
self._ConfigureSuperproject(
opt, manifest, revision=opt.superproject_revision
)
sync_result = manifest.superproject.Sync(self.git_event_log)
if not sync_result.success:
raise SyncError("failed to sync superproject")
cmd = ["show", f"{opt.superproject_revision}:.supermanifest"]
p = GitCommand(
None,
cmd,
gitdir=manifest.superproject._work_git,
bare=True,
capture_stdout=True,
capture_stderr=True,
)
if p.Wait() != 0:
raise SyncError(
f"failed to read .supermanifest from superproject: {p.stderr}"
)
try:
_, _, manifest_commit = p.stdout.strip().split()
except ValueError:
raise SyncError("could not parse .supermanifest")
mp.SetRevision(manifest_commit)
try:
self._UpdateManifestProject(opt, mp, manifest_name, errors)
except UpdateManifestError as e:
raise SyncError(
"failed to sync manifest project", aggregate_errors=[e]
)
def _ExecuteHelper(self, opt, args, errors):
manifest = self.outer_manifest
if not opt.outer_manifest:
@@ -2099,7 +2170,7 @@ later is required to fix a server side protocol bug.
):
mp.ConfigureCloneFilterForDepth("blob:none")
if opt.mp_update:
if opt.mp_update or opt.superproject_revision:
self._UpdateAllManifestProjects(opt, mp, manifest_name, errors)
else:
print("Skipping update of local manifest project.")