Skip to content

macOS: git hooks reject Homebrew [email protected] shebang paths and silently skip graph rebuilds #473

Closed

Description

@ocsarpo

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.11

The 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="" ;;
esac

That pattern rejects valid Homebrew interpreter paths containing @, for example:

/opt/homebrew/opt/[email protected]/bin/python3.11

After that, the fallback chain runs:

  1. GRAPHIFY_PYTHON becomes empty
  2. the hook tries python3 -c "import graphify"
  3. on my machine python3 is /Library/Developer/CommandLineTools/usr/bin/python3
  4. that interpreter does not have graphify installed
  5. the hook exits 0 without rebuilding the graph

Repro

  1. Install graphifyy into a Homebrew-managed Python environment whose executable path contains @, for example [email protected]
  2. Confirm graphify has a shebang like:
    #!/opt/homebrew/opt/[email protected]/bin/python3.11
  3. Run graphify hook install in a git repo that already has graphify-out/graph.json
  4. Make a commit touching a code file, or switch branches
  5. Observe that the hook does not rebuild the graph

Actual behavior

  • post-commit / post-checkout hooks are installed
  • the shebang-derived interpreter path is discarded during sanitization
  • fallback python3 may not contain graphify
  • 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
  • graphify executable: ~/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

  1. safishamsi commented on Apr 21, 2026

    @safishamsi
    Member

    Fixed in v0.4.24: the git hook allowlist now permits @ so Homebrew Python paths like /opt/homebrew/opt/[email protected]/bin/python3.11 pass through correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions