From 0176586544d36d2902d6b8442ea4dc78e7921b8e Mon Sep 17 00:00:00 2001 From: Jacky Liu Date: Mon, 16 Mar 2026 13:07:39 +0800 Subject: Use git_superproject.UseSuperproject() everywhere Currently somewhere use git_superproject.UseSuperproject(), which checks both the manifest config and user's config, and otherwhere use manifest.manifestProject.use_superproject, which only checks the manifest config. This causes Inconsistent behaviors for users who do not set --use-superproject when doing repo init but have repo.superprojectChoice in their git config. Replace where using manifest.manifestProject.use_superproject with git_superproject.UseSuperproject() to respect user's config and avoid inconsistency. Bug: 454514213 Change-Id: I1f734235cdd67b8a6915f1d05967d1aaa4d03f2a Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/561801 Commit-Queue: Jacky Liu Reviewed-by: Mike Frysinger Tested-by: Jacky Liu --- project.py | 31 ++++++++++++++++++++++++------- subcmds/sync.py | 4 ++++ subcmds/upload.py | 3 ++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/project.py b/project.py index caeaa5211..5ac5320ce 100644 --- a/project.py +++ b/project.py @@ -28,7 +28,7 @@ import sys import tarfile import tempfile import time -from typing import List, NamedTuple +from typing import List, NamedTuple, Optional import urllib.parse from color import Coloring @@ -1245,6 +1245,7 @@ class Project: verbose=False, output_redir=None, is_new=None, + use_superproject=None, current_branch_only=None, force_sync=False, clone_bundle=True, @@ -1399,7 +1400,9 @@ class Project: if not ( optimized_fetch and IsId(self.revisionExpr) - and self._CheckForImmutableRevision() + and self._CheckForImmutableRevision( + use_superproject=use_superproject + ) ): remote_fetched = True try: @@ -1409,6 +1412,7 @@ class Project: verbose=verbose, output_redir=output_redir, alt_dir=alt_dir, + use_superproject=use_superproject, current_branch_only=current_branch_only, tags=tags, prune=prune, @@ -2397,7 +2401,9 @@ class Project: return None - def _CheckForImmutableRevision(self): + def _CheckForImmutableRevision( + self, use_superproject: Optional[bool] = None + ) -> bool: try: # if revision (sha or tag) is not present then following function # throws an error. @@ -2405,7 +2411,9 @@ class Project: upstream_rev = None # Only check upstream when using superproject. - if self.upstream and self.manifest.manifestProject.use_superproject: + if self.upstream and git_superproject.UseSuperproject( + use_superproject, self.manifest + ): upstream_rev = self.GetRemote().ToLocal(self.upstream) revs.append(upstream_rev) @@ -2419,7 +2427,9 @@ class Project: # Only verify upstream relationship for superproject scenarios # without affecting plain usage. - if self.upstream and self.manifest.manifestProject.use_superproject: + if self.upstream and git_superproject.UseSuperproject( + use_superproject, self.manifest + ): self.bare_git.merge_base( "--is-ancestor", self.revisionExpr, @@ -2450,6 +2460,7 @@ class Project: def _RemoteFetch( self, name=None, + use_superproject=None, current_branch_only=False, initial=False, quiet=False, @@ -2489,7 +2500,9 @@ class Project: tag_name = self.upstream[len(R_TAGS) :] if is_sha1 or tag_name is not None: - if self._CheckForImmutableRevision(): + if self._CheckForImmutableRevision( + use_superproject=use_superproject + ): if verbose: print( "Skipped fetching project %s (already have " @@ -2809,7 +2822,9 @@ class Project: # We just synced the upstream given branch; verify we # got what we wanted, else trigger a second run of all # refs. - if not self._CheckForImmutableRevision(): + if not self._CheckForImmutableRevision( + use_superproject=use_superproject + ): # Sync the current branch only with depth set to None. # We always pass depth=None down to avoid infinite recursion. return self._RemoteFetch( @@ -2817,6 +2832,7 @@ class Project: quiet=quiet, verbose=verbose, output_redir=output_redir, + use_superproject=use_superproject, current_branch_only=current_branch_only and depth, initial=False, alt_dir=alt_dir, @@ -4827,6 +4843,7 @@ class ManifestProject(MetaProject): quiet=not verbose, verbose=verbose, clone_bundle=clone_bundle, + use_superproject=use_superproject, current_branch_only=current_branch_only, tags=tags, submodules=submodules, diff --git a/subcmds/sync.py b/subcmds/sync.py index 89b58e6aa..03c0eba64 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -808,6 +808,7 @@ later is required to fix a server side protocol bug. quiet=opt.quiet, verbose=opt.verbose, output_redir=buf, + use_superproject=opt.use_superproject, current_branch_only=cls._GetCurrentBranchOnly( opt, project.manifest ), @@ -1499,6 +1500,7 @@ later is required to fix a server side protocol bug. quiet=opt.quiet, verbose=opt.verbose, output_redir=buf, + use_superproject=opt.use_superproject, current_branch_only=self._GetCurrentBranchOnly( opt, manifest ), @@ -1830,6 +1832,7 @@ later is required to fix a server side protocol bug. quiet=not opt.verbose, output_redir=buf, verbose=opt.verbose, + use_superproject=opt.use_superproject, current_branch_only=self._GetCurrentBranchOnly( opt, mp.manifest ), @@ -2356,6 +2359,7 @@ later is required to fix a server side protocol bug. quiet=opt.quiet, verbose=opt.verbose, output_redir=network_output_capture, + use_superproject=opt.use_superproject, current_branch_only=cls._GetCurrentBranchOnly( opt, project.manifest ), diff --git a/subcmds/upload.py b/subcmds/upload.py index 4f817ddfb..60bbb006e 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -27,6 +27,7 @@ from error import SilentRepoExitError from error import UploadError from git_command import GitCommand from git_refs import R_HEADS +import git_superproject from hooks import RepoHook from project import ReviewableBranch from repo_logging import RepoLogger @@ -627,7 +628,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/ # If using superproject, add the root repo as a push option. manifest = branch.project.manifest push_options = list(opt.push_options) - if manifest.manifestProject.use_superproject: + if git_superproject.UseSuperproject(None, manifest): sp = manifest.superproject if sp: r_id = sp.repo_id -- cgit v1.2.3-54-g00ecf