Isolate git environment for all tests

Move the _isolated_git fixture to tests/conftest.py so git rebase --exec
cannot leak GIT_DIR into any test; add a test outside tests/evals.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
torbenandClaude Sonnet 5.5 committed 2026-12-05 07:15:13 +01:00
1 parent ecf4ec4e8a
commit 4bcb1d6596
3 files changed
+36 -16

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
import os
import pytest
# Only these git variables survive; they keep the user's and system git config out.
_GIT_ENV: dict[str, str] = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"}
def pytest_configure(config: pytest.Config) -> None:
"""Keep git in tests away from the repository and config running them.
`git rebase --exec` and hooks export GIT_DIR and friends, `git -c` exports
GIT_CONFIG_PARAMETERS; without this, `git init` and `git commit` in a test
would act on the checkout itself or run its hooks. Runs before collection,
so session fixtures and import-time code are covered too.
"""
for name in [name for name in os.environ if name.startswith("GIT_")]:
del os.environ[name]
os.environ.update(_GIT_ENV)