Skip to content

pre-commit hook leaks GIT_INDEX_FILE into linked-worktree tests #1740

Closed

Description

@bmcnaboe

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

Activity

  1. added
    bugSomething isn't working
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    github_actionsPull requests that update GitHub Actions code
    on Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggithub_actionsPull requests that update GitHub Actions codepriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions