mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-06-03 08:29:48 +00:00
project: support reftable anchors in worktree .git migration
The reftable backend creates real refs/ and reftable/ dirs. Update _MigrateOldWorkTreeGitDir to expect these dirs and remove them. Bug: 476209856 Change-Id: I4700da70cb466e25ecbc51ba4de9a906b8716bd8 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/550761 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
+27
-3
@@ -3632,14 +3632,20 @@ class Project:
|
|||||||
here. The path updates will happen independently.
|
here. The path updates will happen independently.
|
||||||
"""
|
"""
|
||||||
# Figure out where in .repo/projects/ it's pointing to.
|
# Figure out where in .repo/projects/ it's pointing to.
|
||||||
if not os.path.islink(os.path.join(dotgit, "refs")):
|
gitdir = None
|
||||||
|
for name in ("refs", "reftable", "objects"):
|
||||||
|
path = os.path.join(dotgit, name)
|
||||||
|
if os.path.islink(path):
|
||||||
|
gitdir = os.path.dirname(os.path.realpath(path))
|
||||||
|
break
|
||||||
|
else:
|
||||||
raise GitError(
|
raise GitError(
|
||||||
f"{dotgit}: unsupported checkout state", project=project
|
f"{dotgit}: unsupported checkout state", project=project
|
||||||
)
|
)
|
||||||
gitdir = os.path.dirname(os.path.realpath(os.path.join(dotgit, "refs")))
|
|
||||||
|
|
||||||
# Remove known symlink paths that exist in .repo/projects/.
|
# Remove known symlink paths that exist in .repo/projects/.
|
||||||
KNOWN_LINKS = {
|
KNOWN_LINKS = {
|
||||||
|
# go/keep-sorted start
|
||||||
"config",
|
"config",
|
||||||
"description",
|
"description",
|
||||||
"hooks",
|
"hooks",
|
||||||
@@ -3648,9 +3654,11 @@ class Project:
|
|||||||
"objects",
|
"objects",
|
||||||
"packed-refs",
|
"packed-refs",
|
||||||
"refs",
|
"refs",
|
||||||
|
"reftable",
|
||||||
"rr-cache",
|
"rr-cache",
|
||||||
"shallow",
|
"shallow",
|
||||||
"svn",
|
"svn",
|
||||||
|
# go/keep-sorted end
|
||||||
}
|
}
|
||||||
# Paths that we know will be in both, but are safe to clobber in
|
# Paths that we know will be in both, but are safe to clobber in
|
||||||
# .repo/projects/.
|
# .repo/projects/.
|
||||||
@@ -3675,7 +3683,16 @@ class Project:
|
|||||||
dotgit_path = os.path.join(dotgit, name)
|
dotgit_path = os.path.join(dotgit, name)
|
||||||
if name in KNOWN_LINKS:
|
if name in KNOWN_LINKS:
|
||||||
if not platform_utils.islink(dotgit_path):
|
if not platform_utils.islink(dotgit_path):
|
||||||
unknown_paths.append(f"{dotgit_path}: should be a symlink")
|
# In reftable format, refs and reftable can be directories.
|
||||||
|
if name in ("refs", "reftable") and platform_utils.isdir(
|
||||||
|
dotgit_path
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
unknown_paths.append(
|
||||||
|
f"{dotgit_path}: should be a symlink"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
gitdir_path = os.path.join(gitdir, name)
|
gitdir_path = os.path.join(gitdir, name)
|
||||||
if name not in SAFE_TO_CLOBBER and os.path.exists(gitdir_path):
|
if name not in SAFE_TO_CLOBBER and os.path.exists(gitdir_path):
|
||||||
@@ -3697,6 +3714,13 @@ class Project:
|
|||||||
if name.endswith("~") or (name[0] == "#" and name[-1] == "#"):
|
if name.endswith("~") or (name[0] == "#" and name[-1] == "#"):
|
||||||
platform_utils.remove(dotgit_path)
|
platform_utils.remove(dotgit_path)
|
||||||
elif name in KNOWN_LINKS:
|
elif name in KNOWN_LINKS:
|
||||||
|
if (
|
||||||
|
name in ("refs", "reftable")
|
||||||
|
and platform_utils.isdir(dotgit_path)
|
||||||
|
and not platform_utils.islink(dotgit_path)
|
||||||
|
):
|
||||||
|
platform_utils.rmtree(dotgit_path)
|
||||||
|
else:
|
||||||
platform_utils.remove(dotgit_path)
|
platform_utils.remove(dotgit_path)
|
||||||
else:
|
else:
|
||||||
gitdir_path = os.path.join(gitdir, name)
|
gitdir_path = os.path.join(gitdir, name)
|
||||||
|
|||||||
@@ -341,6 +341,7 @@ class MigrateWorkTreeTests(unittest.TestCase):
|
|||||||
"""Check _MigrateOldWorkTreeGitDir handling."""
|
"""Check _MigrateOldWorkTreeGitDir handling."""
|
||||||
|
|
||||||
_SYMLINKS = {
|
_SYMLINKS = {
|
||||||
|
# go/keep-sorted start
|
||||||
"config",
|
"config",
|
||||||
"description",
|
"description",
|
||||||
"hooks",
|
"hooks",
|
||||||
@@ -349,9 +350,11 @@ class MigrateWorkTreeTests(unittest.TestCase):
|
|||||||
"objects",
|
"objects",
|
||||||
"packed-refs",
|
"packed-refs",
|
||||||
"refs",
|
"refs",
|
||||||
|
"reftable",
|
||||||
"rr-cache",
|
"rr-cache",
|
||||||
"shallow",
|
"shallow",
|
||||||
"svn",
|
"svn",
|
||||||
|
# go/keep-sorted end
|
||||||
}
|
}
|
||||||
_FILES = {
|
_FILES = {
|
||||||
"COMMIT_EDITMSG",
|
"COMMIT_EDITMSG",
|
||||||
@@ -430,6 +433,25 @@ class MigrateWorkTreeTests(unittest.TestCase):
|
|||||||
for name in self._SYMLINKS:
|
for name in self._SYMLINKS:
|
||||||
self.assertTrue((dotgit / name).is_symlink())
|
self.assertTrue((dotgit / name).is_symlink())
|
||||||
|
|
||||||
|
def test_reftable_anchor_with_refs_dir(self):
|
||||||
|
"""Migrate when reftable/ and refs/ are directories."""
|
||||||
|
with self._simple_layout() as tempdir:
|
||||||
|
dotgit = tempdir / "src/test/.git"
|
||||||
|
(dotgit / "refs").unlink()
|
||||||
|
(dotgit / "refs").mkdir()
|
||||||
|
(dotgit / "refs" / "heads").write_text("dummy")
|
||||||
|
|
||||||
|
(dotgit / "reftable").unlink()
|
||||||
|
(dotgit / "reftable").mkdir()
|
||||||
|
(dotgit / "reftable" / "tables.list").write_text("dummy")
|
||||||
|
project.Project._MigrateOldWorkTreeGitDir(str(dotgit))
|
||||||
|
|
||||||
|
self.assertTrue(dotgit.is_symlink())
|
||||||
|
self.assertEqual(
|
||||||
|
os.readlink(dotgit),
|
||||||
|
os.path.normpath("../../.repo/projects/src/test.git"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ManifestPropertiesFetchedCorrectly(unittest.TestCase):
|
class ManifestPropertiesFetchedCorrectly(unittest.TestCase):
|
||||||
"""Ensure properties are fetched properly."""
|
"""Ensure properties are fetched properly."""
|
||||||
|
|||||||
Reference in New Issue
Block a user