Skip to content

fix(git): keep git commands off an inherited GIT_DIR - #1358

Merged
BryanFRD merged 2 commits into
mainfrom
fix/test-git-env-leak
Oct 28, 2026
Merged

BryanFRD merged 2 commits into
mainfrom
fix/test-git-env-leak

Conversation

@BryanFRD

Copy link
Copy Markdown
Contributor

Summary

cargo test run from the cargo-husky pre-commit hook inherits GIT_DIR, GIT_INDEX_FILE and friends. git init in 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 from git rev-parse --local-env-vars; all test git spawns use it.
  • New 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 inherited GIT_DIR made the CLI act on a different repo than gix opened. GIT_CONFIG_* is kept so CI-injected config still applies.
  • Identity tests clear GIT_AUTHOR_*/GIT_COMMITTER_*/GIT_CONFIG_PARAMETERS, which git exports to commit hooks.
  • gomod test repo disables tag.gpgsign, matching init_repo_at.
  • Regression test: GIT_DIR pointed at a decoy repo, checks init and production git both target the temp repo and the decoy config is untouched.

Checklist

  • Tests pass (cargo test, also with GIT_DIR=$(git rev-parse --git-dir) and through the real pre-commit hook)
  • No clippy warnings (cargo clippy)
  • Code is formatted (cargo fmt)
  • Documentation updated (if applicable)

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>

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: nothing blocking, one nit inline.

Comment thread src/git_cmd.rs Resolved
Signed-off-by: BryanFRD <bryanferrando59@gmail.com>

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: bench nit fixed in 7144c3c, nothing blocking.

@BryanFRD
BryanFRD merged commit 325710d into main Oct 28, 2026
34 checks passed
@BryanFRD
BryanFRD deleted the fix/test-git-env-leak branch October 28, 2026 08:22
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)
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