summaryrefslogtreecommitdiffstats
path: root/subcmds
diff options
context:
space:
mode:
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.")