Run each side's tests in a committed copy, so tests that call git work

This commit is contained in:
2026-12-03 12:39:28 +01:00
parent 406ee6f99a
commit c1412f598c
3 changed files with 20 additions and 5 deletions
+6 -2
View File
@@ -103,12 +103,16 @@ def committed(git: Git, tree: str) -> Failure | None:
return None
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure:
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree."""
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path, git: Git) -> Ran | Failure:
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree. The copy is
committed first, since a project's tests may call git and a tree from `git archive` holds no repository."""
copy = folder / "tested"
copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True))
if isinstance(copied, Failure):
return copied
if failure := committed(git, str(copy)):
shutil.rmtree(copy, ignore_errors=True)
return failure
try:
return ran_tests(containers, str(copy))
finally: