diff options
| author | Mike Frysinger <vapier@google.com> | 2021-11-13 23:29:42 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-12-01 15:27:16 +0000 |
| commit | 2a089cfee4a3eb0c28cfb441861fc1fcb05797d3 (patch) | |
| tree | 6e876b45921426afa477472aeb5291e9e31071f0 /tests/test_project.py | |
| parent | 4a478edb443864561089b2699c9e65c85fc5e036 (diff) | |
| download | git-repo-2a089cfee4a3eb0c28cfb441861fc1fcb05797d3.tar.gz | |
project: migrate worktree .git/ dirs to symlinksv2.19
Historically we created a .git/ subdir in each source checkout and
symlinked individual files to the .repo/projects/ paths. This layer
of indirection isn't actually needed: the .repo/projects/ paths are
guaranteed to only ever have a 1-to-1 mapping with the actual git
checkout. So we don't need to worry about having files in .git/ be
isolated.
To that end, change how we manage the actual project checkouts from
a dir full of symlinks (and a few files) to a symlink to the internal
.repo/projects/ dir. This makes the code simpler & faster.
The directory structure we have today is:
.repo/
project-objects/chromiumos/third_party/kernel.git/
<paths omitted as not relevant to this change>
projects/src/third_party/kernel/
v3.8.git/
config
description -> …/project-objects/…/config
FETCH_HEAD
HEAD
hooks/ -> …/project-objects/…/hooks/
info/ -> …/project-objects/…/info/
logs/
objects/ -> …/project-objects/…/objects/
packed-refs
refs/
rr-cache/ -> …/project-objects/…/rr-cache/
src/third_party/kernel/
v3.8/
.git/
config -> …/projects/…/v3.8.git/config
description -> …/project-objects/…/v3.8.git/description
HEAD
hooks/ -> …/project-objects/…/v3.8.git/hooks/
index
info/ -> …/project-objects/…/v3.8.git/info/
logs/ -> …/projects/…/v3.8.git/logs/
objects/ -> …/project-objects/…/v3.8.git/objects/
packed-refs -> …/projects/…/v3.8.git/packed-refs
refs/ -> …/projects/…/v3.8.git/refs/
rr-cache/ -> …/project-objects/…/v3.8.git/rr-cache/
The directory structure we have after this commit:
.repo/
<nothing changes>
src/third_party/kernel/
v3.8/
.git -> …/projects/…/v3.8.git
Bug: https://crbug.com/gerrit/15273
Change-Id: I9dd8def23fbfb2f4cb209a93f8b1b2b24002a444
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/323695
Reviewed-by: Mike Nichols <mikenichols@google.com>
Reviewed-by: Xin Li <delphij@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_project.py')
| -rw-r--r-- | tests/test_project.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_project.py b/tests/test_project.py index 9b2cc4e9..d578fe84 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | import contextlib | 17 | import contextlib |
| 18 | import os | 18 | import os |
| 19 | from pathlib import Path | ||
| 19 | import shutil | 20 | import shutil |
| 20 | import subprocess | 21 | import subprocess |
| 21 | import tempfile | 22 | import tempfile |
| @@ -335,3 +336,52 @@ class LinkFile(CopyLinkTestCase): | |||
| 335 | platform_utils.symlink(self.tempdir, dest) | 336 | platform_utils.symlink(self.tempdir, dest) |
| 336 | lf._Link() | 337 | lf._Link() |
| 337 | self.assertEqual(os.path.join('git-project', 'foo.txt'), os.readlink(dest)) | 338 | self.assertEqual(os.path.join('git-project', 'foo.txt'), os.readlink(dest)) |
| 339 | |||
| 340 | |||
| 341 | class MigrateWorkTreeTests(unittest.TestCase): | ||
| 342 | """Check _MigrateOldWorkTreeGitDir handling.""" | ||
| 343 | |||
| 344 | _SYMLINKS = { | ||
| 345 | 'config', 'description', 'hooks', 'info', 'logs', 'objects', | ||
| 346 | 'packed-refs', 'refs', 'rr-cache', 'shallow', 'svn', | ||
| 347 | } | ||
| 348 | _FILES = { | ||
| 349 | 'COMMIT_EDITMSG', 'FETCH_HEAD', 'HEAD', 'index', 'ORIG_HEAD', | ||
| 350 | } | ||
| 351 | |||
| 352 | @classmethod | ||
| 353 | @contextlib.contextmanager | ||
| 354 | def _simple_layout(cls): | ||
| 355 | """Create a simple repo client checkout to test against.""" | ||
| 356 | with tempfile.TemporaryDirectory() as tempdir: | ||
| 357 | tempdir = Path(tempdir) | ||
| 358 | |||
| 359 | gitdir = tempdir / '.repo/projects/src/test.git' | ||
| 360 | gitdir.mkdir(parents=True) | ||
| 361 | cmd = ['git', 'init', '--bare', str(gitdir)] | ||
| 362 | subprocess.check_call(cmd) | ||
| 363 | |||
| 364 | dotgit = tempdir / 'src/test/.git' | ||
| 365 | dotgit.mkdir(parents=True) | ||
| 366 | for name in cls._SYMLINKS: | ||
| 367 | (dotgit / name).symlink_to(f'../../../.repo/projects/src/test.git/{name}') | ||
| 368 | for name in cls._FILES: | ||
| 369 | (dotgit / name).write_text(name) | ||
| 370 | |||
| 371 | subprocess.run(['tree', '-a', str(dotgit)]) | ||
| 372 | yield tempdir | ||
| 373 | |||
| 374 | def test_standard(self): | ||
| 375 | """Migrate a standard checkout that we expect.""" | ||
| 376 | with self._simple_layout() as tempdir: | ||
| 377 | dotgit = tempdir / 'src/test/.git' | ||
| 378 | project.Project._MigrateOldWorkTreeGitDir(str(dotgit)) | ||
| 379 | |||
| 380 | # Make sure the dir was transformed into a symlink. | ||
| 381 | self.assertTrue(dotgit.is_symlink()) | ||
| 382 | self.assertEqual(str(dotgit.readlink()), '../../.repo/projects/src/test.git') | ||
| 383 | |||
| 384 | # Make sure files were moved over. | ||
| 385 | gitdir = tempdir / '.repo/projects/src/test.git' | ||
| 386 | for name in self._FILES: | ||
| 387 | self.assertEqual(name, (gitdir / name).read_text()) | ||
