summaryrefslogtreecommitdiffstats
path: root/tests/test_project.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_project.py')
-rw-r--r--tests/test_project.py50
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
17import contextlib 17import contextlib
18import os 18import os
19from pathlib import Path
19import shutil 20import shutil
20import subprocess 21import subprocess
21import tempfile 22import 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
341class 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())