project: fix m/ generation when switching manifest branches

We were updating the per-checkout m/ pseudo ref when syncing, but we
only created the common m/ redirect when initializing a project for
the first time.  This is fine unless the user switches the manifest
branch in an existing project, then we never create that redirect.

Bug: https://crbug.com/gerrit/14468
Change-Id: I5325e7e602dcb4ce150bef258901ba5e9fdea461
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/304822
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2021-05-01 09:37:13 -04:00
parent 3b038cecc4
commit 29626b4f46

View File

@ -2443,14 +2443,6 @@ class Project(object):
self.bare_objdir.init() self.bare_objdir.init()
if self.use_git_worktrees: if self.use_git_worktrees:
# Set up the m/ space to point to the worktree-specific ref space.
# We'll update the worktree-specific ref space on each checkout.
if self.manifest.branch:
self.bare_git.symbolic_ref(
'-m', 'redirecting to worktree scope',
R_M + self.manifest.branch,
R_WORKTREE_M + self.manifest.branch)
# Enable per-worktree config file support if possible. This is more a # Enable per-worktree config file support if possible. This is more a
# nice-to-have feature for users rather than a hard requirement. # nice-to-have feature for users rather than a hard requirement.
if git_require((2, 20, 0)): if git_require((2, 20, 0)):
@ -2587,6 +2579,14 @@ class Project(object):
def _InitMRef(self): def _InitMRef(self):
if self.manifest.branch: if self.manifest.branch:
if self.use_git_worktrees: if self.use_git_worktrees:
# Set up the m/ space to point to the worktree-specific ref space.
# We'll update the worktree-specific ref space on each checkout.
ref = R_M + self.manifest.branch
if not self.bare_ref.symref(ref):
self.bare_git.symbolic_ref(
'-m', 'redirecting to worktree scope',
ref, R_WORKTREE_M + self.manifest.branch)
# We can't update this ref with git worktrees until it exists. # We can't update this ref with git worktrees until it exists.
# We'll wait until the initial checkout to set it. # We'll wait until the initial checkout to set it.
if not os.path.exists(self.worktree): if not os.path.exists(self.worktree):