Repository navigation
macOS: git hooks reject Homebrew [email protected] shebang paths and silently skip graph rebuilds #473
Description
Summary
On macOS, the git hooks installed by graphify hook install can silently skip graph rebuilds when the graphify executable uses a Homebrew Python shebang such as:
#!/opt/homebrew/opt/[email protected]/bin/python3.11The hook reads the shebang, sanitizes it through an allowlist, and rejects the path because @ is not allowed. It then falls back to python3, which may point to the Xcode Command Line Tools Python instead of the interpreter where graphify is installed. In that case, import graphify fails and the hook exits successfully without rebuilding the graph.
Root cause
The shared _PYTHON_DETECT constant in graphify/hooks.py uses this allowlist:
case "$GRAPHIFY_PYTHON" in
*[!a-zA-Z0-9/_.-]*) GRAPHIFY_PYTHON="" ;;
esacThat pattern rejects valid Homebrew interpreter paths containing @, for example:
/opt/homebrew/opt/[email protected]/bin/python3.11
After that, the fallback chain runs:
GRAPHIFY_PYTHONbecomes empty- the hook tries
python3 -c "import graphify" - on my machine
python3is/Library/Developer/CommandLineTools/usr/bin/python3 - that interpreter does not have
graphifyinstalled - the hook exits
0without rebuilding the graph
Repro
- Install
graphifyyinto a Homebrew-managed Python environment whose executable path contains@, for example[email protected] - Confirm
graphifyhas a shebang like:#!/opt/homebrew/opt/[email protected]/bin/python3.11 - Run
graphify hook installin a git repo that already hasgraphify-out/graph.json - Make a commit touching a code file, or switch branches
- Observe that the hook does not rebuild the graph
Actual behavior
post-commit/post-checkouthooks are installed- the shebang-derived interpreter path is discarded during sanitization
- fallback
python3may not containgraphify - the hook exits silently with no rebuild
Expected behavior
A valid Homebrew Python path such as /opt/homebrew/opt/[email protected]/bin/python3.11 should be accepted, and the hook should use that interpreter to import and run graphify.
Suggested fix
Allow @ in the interpreter path allowlist by updating the shared _PYTHON_DETECT constant in graphify/hooks.py:
case "$GRAPHIFY_PYTHON" in
*[!a-zA-Z0-9/_.@-]*) GRAPHIFY_PYTHON="" ;;
esac_PYTHON_DETECT is reused by both generated git hook scripts, so a single source change fixes both post-commit and post-checkout.
For users who already have the hooks installed, rerunning graphify hook install alone may not regenerate the existing hook files, because the installer currently treats them as already installed. They may need to run graphify hook uninstall followed by graphify hook install, unless the installer is also updated to replace existing graphify-managed hook sections.
Environment
- OS: macOS
- package:
graphifyy 0.4.18 graphifyexecutable:~/Library/Python/3.11/bin/graphify- shebang:
#!/opt/homebrew/opt/[email protected]/bin/python3.11 - fallback
python3:/Library/Developer/CommandLineTools/usr/bin/python3
Temporary workaround
Patch the generated git hooks, or the hook template, to allow @ in the shebang-derived interpreter path.
Activity
safishamsi commentedon Apr 21, 2026
Fixed in v0.4.24: the git hook allowlist now permits
@so Homebrew Python paths like/opt/homebrew/opt/[email protected]/bin/python3.11pass through correctly.