codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

pre-commit hook leaks GIT_INDEX_FILE into linked-worktree tests

Open bmcnaboe opened this issue 3 months ago • 0 comments

Description

With core.hooksPath=scripts/hooks, running git commit reaches the pre-commit hook's full test step but fails git_context_linked_worktree.

Reproduction

  1. Configure the repository hook: git config core.hooksPath scripts/hooks.
  2. Stage any change and run git commit.
  3. Observe the sequential test failure:
git_context_linked_worktree
FAIL tests/test_pipeline.c:6855: run_cmd(cmd) == 32768, expected 0 == 0

The failure can be reproduced without a commit:

GIT_INDEX_FILE=.git/index build/c/test-runner pipeline

This yields 249 passed and 1 failed. The same pipeline suite passes 250/250 when the repository-local Git environment is absent.

Root cause

Git exports repository-local variables such as GIT_INDEX_FILE=.git/index to hooks. The test runner inherits that value. It works while a fixture uses a normal .git directory, but git worktree add checks out into a linked worktree where .git is a file, so the inherited .git/index path is invalid.

Expected behavior

The hook should preserve Git's staged-index environment for diff-scoped linting, then clear repository-local Git variables only for the test subprocess.

Validation

After isolating the test subprocess environment:

  • poisoned-environment pipeline regression: 250 passed
  • real pre-commit hook: 7,555 passed, 8 skipped
  • canonical scripts/test.sh: 7,555 passed, 0 failed, 8 skipped

bmcnaboe avatar Aug 19 '26 15:08 bmcnaboe