Skip to content

fix(hooks): run pre-commit checks without git's GIT_DIR/GIT_INDEX_FILE - #15

Merged
Ian-Tharp merged 1 commit into
developfrom
fix/pre-commit-git-env-isolation
Nov 4, 2026
Merged

Ian-Tharp merged 1 commit into
developfrom
fix/pre-commit-git-env-isolation

Conversation

@Ian-Tharp

Copy link
Copy Markdown
Owner

Git exports GIT_DIR and GIT_INDEX_FILE to hooks. tests/test_tool_dispatcher.py runs git init / git config in a tmp dir, so a commit that triggered the pre-commit hook (seen from a worktree) wrote into the real repo config: core.bare=true and a fake user.name=Test / user.email=test@test.com.

Fix: unset the git variables in .githooks/pre-commit before running black and pytest.

Verified: committed a backend test file through the hook from a worktree. Hook ran black + the full suite (3385 passed), and .git/config was byte-identical before and after.

🤖 Generated with Claude Code

Git exports GIT_DIR and GIT_INDEX_FILE to hooks. test_tool_dispatcher's
fixture runs git init/config in a tmp dir, which then wrote to the real
repo config (core.bare=true and a fake user identity). Unset the git
variables before running black and pytest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ian-Tharp
Ian-Tharp merged commit 86b9238 into develop Nov 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant