Skip to content

fix(tests): ignore an inherited git repository environment (#2003) - #2337

Merged
DeusData merged 1 commit into
mainfrom
fix/issue-2003
Oct 2, 2026
Merged

DeusData merged 1 commit into
mainfrom
fix/issue-2003

Conversation

@DeusData

Copy link
Copy Markdown
Owner

Git exports repository-local variables (GIT_DIR, GIT_INDEX_FILE,
GIT_WORK_TREE, ...) into hooks, and they take precedence over
git -C <dir>. Every fixture git command in the test runner therefore
acted on the caller's real repository whenever the suite ran with those
variables set: with GIT_DIR alone, fixture assertions failed and commits,
branches and linked worktrees were written into the caller's clone; with
the full hook set, fixture commits failed and git-dependent tests degraded
to "git not available" SKIPs. The pre-commit hook already clears the
variables (7883507), but any other caller (a shell with GIT_DIR set, an
editor hook, GIT_DIR=... scripts/test.sh) still hit it.

The test runner and the repro runner now clear git's local-env list
(git rev-parse --local-env-vars) once at startup, before any fixture or
re-exec'd child spawns git, so every fixture scopes to its own repository
no matter who invokes the suite.

tests/test_git_env_isolation_contract.sh (Step 3a of scripts/test.sh)
drives the real runner's git_context suite with GIT_DIR, and with the full
hook set, aimed at a throwaway decoy repository. It requires the same
pass/skip summary as a clean run and a decoy left untouched (no refs, no
linked worktrees).


Test-suite half of #2003. The production half (cbm's own git children) is the separate fix/git-spawn-local-env PR; once both land, the test helper can reuse cbm_git_repo_env_vars. Thanks to @metehanulusoy for the report and analysis, and @AmirF194 for the reproduction.

Fixes #2003

Git exports repository-local variables (GIT_DIR, GIT_INDEX_FILE,
GIT_WORK_TREE, ...) into hooks, and they take precedence over
`git -C <dir>`. Every fixture git command in the test runner therefore
acted on the caller's real repository whenever the suite ran with those
variables set: with GIT_DIR alone, fixture assertions failed and commits,
branches and linked worktrees were written into the caller's clone; with
the full hook set, fixture commits failed and git-dependent tests degraded
to "git not available" SKIPs. The pre-commit hook already clears the
variables (7883507), but any other caller (a shell with GIT_DIR set, an
editor hook, `GIT_DIR=... scripts/test.sh`) still hit it.

The test runner and the repro runner now clear git's local-env list
(`git rev-parse --local-env-vars`) once at startup, before any fixture or
re-exec'd child spawns git, so every fixture scopes to its own repository
no matter who invokes the suite.

tests/test_git_env_isolation_contract.sh (Step 3a of scripts/test.sh)
drives the real runner's git_context suite with GIT_DIR, and with the full
hook set, aimed at a throwaway decoy repository. It requires the same
pass/skip summary as a clean run and a decoy left untouched (no refs, no
linked worktrees).

Signed-off-by: Martin Vogel <[email protected]>
@DeusData
DeusData merged commit 96c3f41 into main Oct 2, 2026
34 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.

pre-commit hook fails the test suite: git exports GIT_DIR into hooks, which overrides git -C in tests/test_pipeline.c

1 participant