From 9b57aa00f6e8136fd49fdbb29cf669c3dafa2c6b Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 1 Dec 2023 23:01:52 +0000 Subject: [PATCH] project: Check references during sync Symbolic references need to be checked each time sync is called, not only for newly created repositories. For example, it is possible to change a project name to the already existing name, and that will result in a broken git setup without this patch: refs/ will still point to the old repository, whereas all objects will point to the new repository. Bug: 40013418 Change-Id: I596d29d182986804989f0562fb45090224549b0f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/395798 Reviewed-by: Mike Frysinger Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- project.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/project.py b/project.py index d887a558..9dc7feae 100644 --- a/project.py +++ b/project.py @@ -1277,7 +1277,20 @@ class Project: if is_new: self._InitGitDir(force_sync=force_sync, quiet=quiet) else: - self._UpdateHooks(quiet=quiet) + try: + # At this point, it's possible that gitdir points to an old + # objdir (e.g. name changed, but objdir exists). Check + # references to ensure that's not the case. See + # https://issues.gerritcodereview.com/40013418 for more + # details. + self._CheckDirReference(self.objdir, self.gitdir) + + self._UpdateHooks(quiet=quiet) + except GitError as e: + if not force_sync: + raise e + # Let _InitGitDir fix the issue, force_sync is always True here. + self._InitGitDir(force_sync=True, quiet=quiet) self._InitRemote() if self.UseAlternates: