From 9776e13f176a51b197498850ae08898789db0ce1 Mon Sep 17 00:00:00 2001 From: Dave Wilding Date: Sat, 31 Oct 2026 00:27:23 -0500 Subject: [PATCH] drop Git env vars `git commit` runs pre-commit hooks with GIT_INDEX_FILE (and friends) exported, pointing at the parent repository's index. That leaks into the nested git subprocesses of tests/unit, whose fresh repositories lack the referenced objects, so their commits die with "Error building trees" and just-unit fails. Scrub the four GIT_* path variables via an autouse fixture so every unit test's Git subprocesses work on their own repositories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/unit/conftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/unit/conftest.py diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py new file mode 100644 index 0000000..d275483 --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,19 @@ +import pytest + + +@pytest.fixture(autouse=True) +def hermetic_git_env(monkeypatch: pytest.MonkeyPatch): + """Drop Git environment variables inherited from the outer process. + + `git commit` runs pre-commit hooks with GIT_INDEX_FILE (and friends) exported, + pointing at the parent repository's index. This fixture prevents Git subprocesses + from reading that index and failing to find objects. + """ + + for var in ( + "GIT_INDEX_FILE", + "GIT_DIR", + "GIT_WORK_TREE", + "GIT_OBJECT_DIRECTORY", + ): + monkeypatch.delenv(var, raising=False)