summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2026-02-07 00:53:31 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2026-03-17 14:30:35 -0700
commit83b8ebdbbed5ec894a2f89eb5e4bcf5d0bb14300 (patch)
treebd84dbdba2f3a8935a4e92704bc2bfee4318be7a /tests
parenta0abfd7339536cfba02c112e7ac804bc6252ebdb (diff)
downloadgit-repo-83b8ebdbbed5ec894a2f89eb5e4bcf5d0bb14300.tar.gz
git_superproject: avoid re-initing bare repo
Running sync with reftable on a files-backed workspace fails to re-init the superproject dir with: ``` fatal: could not open '.../.repo/exp-superproject/<hash>-superproject.git/refs/heads' for writing: Is a directory ``` Bug: 476209856 Change-Id: Ie8473d66069aafefa5661bd3ea8e73b2b27c6a38 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/550981 Commit-Queue: Gavin Mak <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_git_superproject.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index 3ceb9320f..dbfb8385c 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -461,6 +461,62 @@ class SuperprojectTestCase(unittest.TestCase):
461 "</manifest>", 461 "</manifest>",
462 ) 462 )
463 463
464 def test_Init_success(self):
465 """Test _Init succeeds and creates the work git dir."""
466 self.assertFalse(os.path.exists(self._superproject._work_git))
467 with mock.patch(
468 "git_superproject.GitCommand", autospec=True
469 ) as mock_git_command:
470 instance = mock_git_command.return_value
471 instance.Wait.return_value = 0
472
473 self.assertTrue(self._superproject._Init())
474
475 mock_git_command.assert_called_once()
476 args, kwargs = mock_git_command.call_args
477 self.assertEqual(args[1][:2], ["init", "--bare"])
478
479 tmp_git_name = args[1][2]
480 self.assertTrue(
481 tmp_git_name.startswith(".tmp-superproject-initgitdir-")
482 )
483 self.assertTrue(os.path.exists(self._superproject._work_git))
484
485 tmp_git_path = os.path.join(
486 self._superproject._superproject_path, tmp_git_name
487 )
488 self.assertFalse(os.path.exists(tmp_git_path))
489
490 def test_Init_already_exists(self):
491 """Test _Init returns early if the work git dir already exists."""
492 os.mkdir(self._superproject._superproject_path)
493 os.mkdir(self._superproject._work_git)
494 with mock.patch(
495 "git_superproject.GitCommand", autospec=True
496 ) as mock_git_command:
497 self.assertTrue(self._superproject._Init())
498 mock_git_command.assert_not_called()
499
500 def test_Init_failure_cleans_up(self):
501 """Test _Init cleans up the temporary directory if 'git init' fails."""
502 with mock.patch(
503 "git_superproject.GitCommand", autospec=True
504 ) as mock_git_command:
505 instance = mock_git_command.return_value
506 instance.Wait.return_value = 1
507 instance.stderr = "mock git init failure"
508
509 self.assertFalse(self._superproject._Init())
510 mock_git_command.assert_called_once()
511 args, kwargs = mock_git_command.call_args
512 tmp_git_name = args[1][2]
513
514 tmp_git_path = os.path.join(
515 self._superproject._superproject_path, tmp_git_name
516 )
517 self.assertFalse(os.path.exists(tmp_git_path))
518 self.assertFalse(os.path.exists(self._superproject._work_git))
519
464 def test_Fetch(self): 520 def test_Fetch(self):
465 manifest = self.getXmlManifest( 521 manifest = self.getXmlManifest(
466 """ 522 """