diff options
| author | Mike Frysinger <vapier@google.com> | 2022-01-06 05:42:24 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2022-01-07 20:17:14 +0000 |
| commit | 89ed8acdbe468fd76d531cd8b7b2ace5b414f0bd (patch) | |
| tree | f0dcf219ba20bb8e4d74e551ebf3bc0572104a99 /tests/test_project.py | |
| parent | 71e48b76728dcc50b3265d320ee1c2d1ea09a4f5 (diff) | |
| download | git-repo-89ed8acdbe468fd76d531cd8b7b2ace5b414f0bd.tar.gz | |
project: abort a bit earlier before migrating .git/
Verify all the .git/ paths will be handled by the migration logic before
starting the migration. This way we still abort & log an error, but the
user gets to see it before we put the tree into a state that they have to
manually recover. Also add a few more known-safe-to-clobber paths.
Bug: https://crbug.com/gerrit/15273
Change-Id: If49d69b341bc960ddcafa30da333fb5ec7145b51
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/327557
Reviewed-by: Colin Cross <ccross@android.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_project.py')
| -rw-r--r-- | tests/test_project.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/test_project.py b/tests/test_project.py index d578fe84..4f449227 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -347,6 +347,10 @@ class MigrateWorkTreeTests(unittest.TestCase): | |||
| 347 | } | 347 | } |
| 348 | _FILES = { | 348 | _FILES = { |
| 349 | 'COMMIT_EDITMSG', 'FETCH_HEAD', 'HEAD', 'index', 'ORIG_HEAD', | 349 | 'COMMIT_EDITMSG', 'FETCH_HEAD', 'HEAD', 'index', 'ORIG_HEAD', |
| 350 | 'unknown-file-should-be-migrated', | ||
| 351 | } | ||
| 352 | _CLEAN_FILES = { | ||
| 353 | 'a-vim-temp-file~', '#an-emacs-temp-file#', | ||
| 350 | } | 354 | } |
| 351 | 355 | ||
| 352 | @classmethod | 356 | @classmethod |
| @@ -365,10 +369,9 @@ class MigrateWorkTreeTests(unittest.TestCase): | |||
| 365 | dotgit.mkdir(parents=True) | 369 | dotgit.mkdir(parents=True) |
| 366 | for name in cls._SYMLINKS: | 370 | for name in cls._SYMLINKS: |
| 367 | (dotgit / name).symlink_to(f'../../../.repo/projects/src/test.git/{name}') | 371 | (dotgit / name).symlink_to(f'../../../.repo/projects/src/test.git/{name}') |
| 368 | for name in cls._FILES: | 372 | for name in cls._FILES | cls._CLEAN_FILES: |
| 369 | (dotgit / name).write_text(name) | 373 | (dotgit / name).write_text(name) |
| 370 | 374 | ||
| 371 | subprocess.run(['tree', '-a', str(dotgit)]) | ||
| 372 | yield tempdir | 375 | yield tempdir |
| 373 | 376 | ||
| 374 | def test_standard(self): | 377 | def test_standard(self): |
| @@ -385,3 +388,24 @@ class MigrateWorkTreeTests(unittest.TestCase): | |||
| 385 | gitdir = tempdir / '.repo/projects/src/test.git' | 388 | gitdir = tempdir / '.repo/projects/src/test.git' |
| 386 | for name in self._FILES: | 389 | for name in self._FILES: |
| 387 | self.assertEqual(name, (gitdir / name).read_text()) | 390 | self.assertEqual(name, (gitdir / name).read_text()) |
| 391 | # Make sure files were removed. | ||
| 392 | for name in self._CLEAN_FILES: | ||
| 393 | self.assertFalse((gitdir / name).exists()) | ||
| 394 | |||
| 395 | def test_unknown(self): | ||
| 396 | """A checkout with unknown files should abort.""" | ||
| 397 | with self._simple_layout() as tempdir: | ||
| 398 | dotgit = tempdir / 'src/test/.git' | ||
| 399 | (tempdir / '.repo/projects/src/test.git/random-file').write_text('one') | ||
| 400 | (dotgit / 'random-file').write_text('two') | ||
| 401 | with self.assertRaises(error.GitError): | ||
| 402 | project.Project._MigrateOldWorkTreeGitDir(str(dotgit)) | ||
| 403 | |||
| 404 | # Make sure no content was actually changed. | ||
| 405 | self.assertTrue(dotgit.is_dir()) | ||
| 406 | for name in self._FILES: | ||
| 407 | self.assertTrue((dotgit / name).is_file()) | ||
| 408 | for name in self._CLEAN_FILES: | ||
| 409 | self.assertTrue((dotgit / name).is_file()) | ||
| 410 | for name in self._SYMLINKS: | ||
| 411 | self.assertTrue((dotgit / name).is_symlink()) | ||
