Run every tool's git through git_repo.git, with rule-hook's guards as an option

This commit is contained in:
2026-10-21 19:35:15 +02:00
parent 583b85eea8
commit a261669735
15 changed files with 116 additions and 110 deletions
+22
View File
@@ -26,6 +26,28 @@ class Git(unittest.TestCase):
self.assertIn("latin", done.reason)
self.assertIn("UTF-8", done.reason)
def test_says_which_command_could_not_start_in_a_directory_that_is_gone(self):
self.assertEqual(git_repo.git("log", cwd="/code/gone"), Failure("git log could not start: [Errno 2] No such file or directory: '/code/gone'"))
class Guarded(unittest.TestCase):
"""A checkout whose own config allows git's ext transport, which runs a program, for its origin."""
def setUp(self):
temp = tempfile.TemporaryDirectory()
self.addCleanup(temp.cleanup)
self.root = pathlib.Path(temp.name)
for args in (("init", "--quiet"), ("config", "protocol.ext.allow", "always"), ("remote", "add", "origin", "ext::touch ran")):
subprocess.run(["git", *args], capture_output=True, check=True, cwd=self.root)
def test_runs_no_transport_the_checkout_allows(self):
self.assertIsInstance(git_repo.git("ls-remote", "origin", cwd=str(self.root), guarded=True), Failure)
self.assertFalse((self.root / "ran").exists())
def test_runs_it_unguarded(self):
git_repo.git("ls-remote", "origin", cwd=str(self.root))
self.assertTrue((self.root / "ran").exists())
class StalledOrigin(unittest.TestCase):
"""A checkout whose origin, run through git's ext transport, answers nothing for 10 s, and which records no default branch for it."""