summaryrefslogtreecommitdiffstats
path: root/subcmds
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2026-04-22 00:39:42 +0000
committergerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2026-05-20 12:28:55 -0700
commit2d54384a5e59fddd0626ec091cc0ad11511d834e (patch)
treec0a9d642bb4064a23df2044777b6f81f2c047473 /subcmds
parent1b4e7a04be7b49d8c0c5e161d36f209bca4b6498 (diff)
downloadgit-repo-stable.tar.gz
sync: Add --superproject-rev flag to sync to specific revisionv2.64stable
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>
Diffstat (limited to 'subcmds')
-rw-r--r--subcmds/sync.py85
1 files changed, 78 insertions, 7 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 8c2591180..7e0e7418c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -64,6 +64,7 @@ from error import SyncError
64from error import UpdateManifestError 64from error import UpdateManifestError
65import event_log 65import event_log
66from git_command import git_require 66from git_command import git_require
67from git_command import GitCommand
67from git_config import GetUrlCookieFile 68from git_config import GetUrlCookieFile
68from git_refs import HEAD 69from git_refs import HEAD
69from git_refs import R_HEADS 70from git_refs import R_HEADS
@@ -565,6 +566,11 @@ later is required to fix a server side protocol bug.
565 dest="use_superproject", 566 dest="use_superproject",
566 help="disable use of manifest superprojects", 567 help="disable use of manifest superprojects",
567 ) 568 )
569 p.add_option(
570 "--superproject-revision",
571 action="store",
572 help="sync to superproject revision (applies to outer manifest)",
573 )
568 p.add_option("--tags", action="store_true", help="fetch tags") 574 p.add_option("--tags", action="store_true", help="fetch tags")
569 p.add_option( 575 p.add_option(
570 "--no-tags", 576 "--no-tags",
@@ -668,6 +674,24 @@ later is required to fix a server side protocol bug.
668 or opt.current_branch_only 674 or opt.current_branch_only
669 ) 675 )
670 676
677 def _ConfigureSuperproject(
678 self,
679 opt: optparse.Values,
680 manifest,
681 revision: Optional[str] = None,
682 ) -> bool:
683 """Configure superproject with options."""
684 if not manifest.superproject:
685 return False
686 manifest.superproject.SetQuiet(not opt.verbose)
687 print_messages = git_superproject.PrintMessages(
688 opt.use_superproject, manifest
689 )
690 manifest.superproject.SetPrintMessages(print_messages)
691 if revision:
692 manifest.superproject.SetRevisionId(revision)
693 return print_messages
694
671 def _UpdateProjectsRevisionId( 695 def _UpdateProjectsRevisionId(
672 self, opt, args, superproject_logging_data, manifest 696 self, opt, args, superproject_logging_data, manifest
673 ): 697 ):
@@ -741,11 +765,7 @@ later is required to fix a server side protocol bug.
741 765
742 if not use_super: 766 if not use_super:
743 continue 767 continue
744 m.superproject.SetQuiet(not opt.verbose) 768 print_messages = self._ConfigureSuperproject(opt, m)
745 print_messages = git_superproject.PrintMessages(
746 opt.use_superproject, m
747 )
748 m.superproject.SetPrintMessages(print_messages)
749 update_result = m.superproject.UpdateProjectsRevisionId( 769 update_result = m.superproject.UpdateProjectsRevisionId(
750 per_manifest[m.path_prefix], git_event_log=self.git_event_log 770 per_manifest[m.path_prefix], git_event_log=self.git_event_log
751 ) 771 )
@@ -1832,7 +1852,11 @@ later is required to fix a server side protocol bug.
1832 mp: the manifestProject to query. 1852 mp: the manifestProject to query.
1833 manifest_name: Manifest file to be reloaded. 1853 manifest_name: Manifest file to be reloaded.
1834 """ 1854 """
1835 if not mp.standalone_manifest_url: 1855 if opt.superproject_revision and mp.manifest == self.outer_manifest:
1856 self._SyncToSuperprojectRev(
1857 opt, mp.manifest, mp, manifest_name, errors
1858 )
1859 elif not mp.standalone_manifest_url:
1836 self._UpdateManifestProject(opt, mp, manifest_name, errors) 1860 self._UpdateManifestProject(opt, mp, manifest_name, errors)
1837 1861
1838 if mp.manifest.submanifests: 1862 if mp.manifest.submanifests:
@@ -2041,6 +2065,53 @@ later is required to fix a server side protocol bug.
2041 if not success: 2065 if not success:
2042 print("Warning: post-sync hook reported failure.") 2066 print("Warning: post-sync hook reported failure.")
2043 2067
2068 def _SyncToSuperprojectRev(
2069 self,
2070 opt: optparse.Values,
2071 manifest,
2072 mp: Project,
2073 manifest_name: Optional[str],
2074 errors: List[Exception],
2075 ) -> None:
2076 """Sync to a specific superproject commit."""
2077 if not manifest.superproject:
2078 raise SyncError("superproject not defined in manifest")
2079
2080 self._ConfigureSuperproject(
2081 opt, manifest, revision=opt.superproject_revision
2082 )
2083
2084 sync_result = manifest.superproject.Sync(self.git_event_log)
2085 if not sync_result.success:
2086 raise SyncError("failed to sync superproject")
2087
2088 cmd = ["show", f"{opt.superproject_revision}:.supermanifest"]
2089 p = GitCommand(
2090 None,
2091 cmd,
2092 gitdir=manifest.superproject._work_git,
2093 bare=True,
2094 capture_stdout=True,
2095 capture_stderr=True,
2096 )
2097 if p.Wait() != 0:
2098 raise SyncError(
2099 f"failed to read .supermanifest from superproject: {p.stderr}"
2100 )
2101
2102 try:
2103 _, _, manifest_commit = p.stdout.strip().split()
2104 except ValueError:
2105 raise SyncError("could not parse .supermanifest")
2106
2107 mp.SetRevision(manifest_commit)
2108 try:
2109 self._UpdateManifestProject(opt, mp, manifest_name, errors)
2110 except UpdateManifestError as e:
2111 raise SyncError(
2112 "failed to sync manifest project", aggregate_errors=[e]
2113 )
2114
2044 def _ExecuteHelper(self, opt, args, errors): 2115 def _ExecuteHelper(self, opt, args, errors):
2045 manifest = self.outer_manifest 2116 manifest = self.outer_manifest
2046 if not opt.outer_manifest: 2117 if not opt.outer_manifest:
@@ -2099,7 +2170,7 @@ later is required to fix a server side protocol bug.
2099 ): 2170 ):
2100 mp.ConfigureCloneFilterForDepth("blob:none") 2171 mp.ConfigureCloneFilterForDepth("blob:none")
2101 2172
2102 if opt.mp_update: 2173 if opt.mp_update or opt.superproject_revision:
2103 self._UpdateAllManifestProjects(opt, mp, manifest_name, errors) 2174 self._UpdateAllManifestProjects(opt, mp, manifest_name, errors)
2104 else: 2175 else:
2105 print("Skipping update of local manifest project.") 2176 print("Skipping update of local manifest project.")