#14

.githooks/pre-commit leaks GIT_DIR/GIT_INDEX_FILE into pytest — fixture tests that shell out to git corrupt the real repo

Openyonasbopened 3mo ago

Found during the #2 fix build (PR #13). git commit exports GIT_DIR, GIT_INDEX_FILE (and sometimes GIT_WORK_TREE) to hook children. .githooks/pre-commit runs the FULL pytest suite inside the hook, so any test that shells out to git (fixture-repo tests do) inherits those vars and operates on the REAL repository instead of its tmp fixture dir.

Observed effects in a worktree: HEAD reset, index truncated to a single entry, stray init/base fixture commits landing on real refs, and core.bare true written into the primary repo's config.

Fix: unset the inherited env at the top of the hook before invoking pytest:

unset GIT_DIR GIT_INDEX_FILE GIT_WORK_TREE GIT_INDEX_VERSION

Belt-and-braces alternative/addition: make fixture tests that spawn git pass env={...} scrubbed of GIT_*, so the suite is safe under ANY caller, not just this hook.

🤖 Generated with Claude Code

Activity

0

No activity yet.