From 29626b4f463d12186d9ce96e07063214347ead18 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 1 May 2021 09:37:13 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- project.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/project.py b/project.py index 94c13785..f05ce66a 100644 --- a/project.py +++ b/project.py @@ -2443,14 +2443,6 @@ class Project(object): self.bare_objdir.init() 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 # nice-to-have feature for users rather than a hard requirement. if git_require((2, 20, 0)): @@ -2587,6 +2579,14 @@ class Project(object): def _InitMRef(self): if self.manifest.branch: 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'll wait until the initial checkout to set it. if not os.path.exists(self.worktree):