A git hook handed down its environment variables, and fixture tests damaged the real repository
By Fahmi Ghani · about the author and how this is written

When the test gate ran from a pre-push hook, git exported GIT_DIR and GIT_PREFIX to the hook. Child processes of the tests inherited them, so tests that create a temporary repository changed the real one instead. On Windows there is a second cause: the tar that ships with Git Bash reads a drive prefix as a remote host name.
Method
I observed the damage on a working branch (file modes, missing files, a fixture commit), wrote the guard test red first, then fixed it. The guard test runs a slice of the gate with a mimicked hook environment on a temporary repository and compares HEAD, the file list with modes, status, local configuration and file contents before and after. The fix is one function that removes the repository-pointing variables from the environment of every child process.
Numbers
| What was measured | Result |
|---|---|
| Guard tests on the old code | 0 of 6 passed |
| After the variables were scrubbed, under the hook environment | 3 of 6 passed |
| After a small folder holding only a copy of the system tar (bsdtar) was put first in PATH for child processes | 6 of 6 passed |
| Damage seen on the working branch before the fix | file mode 755 became 644; images deleted; one fixture commit appeared |
Limits
- One project on one Windows machine. The six guard tests cover the damage I met, not every possibility.
- The tar fix is deliberately narrow: only tar is replaced and other programs are unchanged. It has been tested on one machine only.
- The full gate on the code base was already red before the fix (noted as 688 passed, 7 failed); I have not examined those seven tests, and the full gate on a clean clone has not been run.
- The variable list is explicit (9 names) instead of removing every GIT_*, so configuration variables such as the commit author identity keep working.
Sources
- Incident notes and guard tests in the affected project repository, work-ledger rows of 23 November 2026 (internal archive, unpublished) · record date 23 November 2026
How it was checked: Quoted from the experiment record; derived figures re-checked, raw files not re-run. This is a synthesis of my own experiments. It is not peer reviewed.
Drafted with AI help from my work notes and experiments; I review it before it is published.
Licence: text and data CC BY 4.0. You may reuse and quote with credit to the author and a link to this page.
Cite as: Ghani, F. (2026). MiganCore Findings, record TMN-012. https://migancore.com/en/blog/research/git-hook-passed-env-variables-down-and-damaged-the-real-repo/ · JSON