Repository navigation
fix(git): keep git commands off an inherited GIT_DIR - #1358
Merged
Merged
Conversation
cargo test run from the pre-commit hook inherits GIT_DIR, GIT_INDEX_FILE and friends, so `git init` in a temp dir wrote to the real repo's config and parallel tests failed with "could not lock config file". Test helpers now build git through test_utils::git_command, which removes every var listed by `git rev-parse --local-env-vars`. Production spawns go through git_cmd::command, which drops the repo-location vars (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, ...). ferrflow opens the repo by path with gix and runs git with current_dir set to that workdir; an inherited GIT_DIR made the CLI act on a different repo than the one gix opened. GIT_CONFIG_* is kept so config injected by CI still applies. The identity tests also clear GIT_AUTHOR_*/GIT_COMMITTER_* and GIT_CONFIG_PARAMETERS, which git exports to commit hooks, and the gomod test repo disables tag.gpgsign, matching init_repo_at. Signed-off-by: BryanFRD <bryanferrando59@gmail.com>
Signed-off-by: BryanFRD <bryanferrando59@gmail.com>
Contributor
There was a problem hiding this comment.
Approve: bench nit fixed in 7144c3c, nothing blocking.
ferrflow Bot
added a commit
that referenced
this pull request
Oct 28, 2026
## [7.35.1] - 2026-10-28 ### Bug Fixes - fix(git): keep git commands off an inherited GIT_DIR (#1358)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cargo testrun from the cargo-husky pre-commit hook inheritsGIT_DIR,GIT_INDEX_FILEand friends.git initin a temp dir then wrote to the real repo's.git/config([user] name = Test,commit.gpgsign = false, ...), parallel tests failed with "could not lock config file", and production git calls under test (reset, checkout, branch) ran against the developer's checkout.Related Issue
None.
Changes
test_utils::git_command()(lib and bin) strips every var fromgit rev-parse --local-env-vars; all test git spawns use it.git_cmd::command()drops the repo-location vars for production spawns. ferrflow opens the repo by path with gix and runs git in that workdir, so an inheritedGIT_DIRmade the CLI act on a different repo than gix opened.GIT_CONFIG_*is kept so CI-injected config still applies.GIT_AUTHOR_*/GIT_COMMITTER_*/GIT_CONFIG_PARAMETERS, which git exports to commit hooks.tag.gpgsign, matchinginit_repo_at.GIT_DIRpointed at a decoy repo, checks init and production git both target the temp repo and the decoy config is untouched.Checklist
cargo test, also withGIT_DIR=$(git rev-parse --git-dir)and through the real pre-commit hook)cargo clippy)cargo fmt)