pub fn strip_git_env(cmd: &mut Command)Expand description
Strip git’s own environment before handing a Command to another tool.
git exports GIT_DIR, GIT_INDEX_FILE, GIT_WORK_TREE and friends to every hook. Those OVERRIDE the working directory, so any tool that shells out to git operates on the hook’s repository no matter where it was launched.
That is not hypothetical: pre-push-cargo-test runs a project’s test suite,
and this repo’s own suite creates throwaway repos and commits to them. With
GIT_DIR inherited, git commit in a test wrote into the REAL repository —
an actual stray commit, authored by the test fixture, pushed to a branch.
A test suite should behave exactly as it does when run by hand, which means seeing no git environment at all.