Research · TMN-012 ·

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

A git hook handed down its environment variables, and fixture tests damaged the real repository
Illustration made with AI.

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 measuredResult
Guard tests on the old code0 of 6 passed
After the variables were scrubbed, under the hook environment3 of 6 passed
After a small folder holding only a copy of the system tar (bsdtar) was put first in PATH for child processes6 of 6 passed
Damage seen on the working branch before the fixfile mode 755 became 644; images deleted; one fixture commit appeared

Limits

Sources

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

NextSee the work log