Skip to content

Windows: post-commit and post-checkout hooks fail with 'python3: command not found' #244

Closed

Description

@arkritico

Summary

On Windows, graphify hook install (v0.4.2) writes post-commit and post-checkout hooks that hardcode python3 as their fallback interpreter. Windows Python installs use python (no python3 shim), so every commit and checkout produces:

.git/hooks/post-commit: line 32: python3: command not found

The hook runs as a silent no-op, so it's not fatal, but the knowledge graph never rebuilds — defeating the purpose of the hook install.

Root cause

The hooks try to sniff the Python interpreter from the graphify binary's shebang line:

GRAPHIFY_BIN=$(command -v graphify 2>/dev/null)
if [ -n "$GRAPHIFY_BIN" ]; then
    _SHEBANG=$(head -1 "$GRAPHIFY_BIN" | sed 's/^#![[:space:]]*//')
    ...

On Windows, graphify is a .exe wrapper (not a Python script with a shebang). head -1 of an .exe returns binary garbage starting with MZ, the allowlist filter rejects it, and the hook falls through to the hardcoded GRAPHIFY_PYTHON="python3" fallback. Since Windows doesn't have python3 on PATH, execution fails.

Repro

  1. Windows 10/11 with Python 3.x installed (so python is on PATH but python3 is not)
  2. pip install graphifyy
  3. cd some-repo && graphify hook install
  4. Make any commit
  5. Observe: python3: command not found on stderr, no graph rebuild happens

Fix

Both post-commit and post-checkout hooks need a cross-platform fallback chain. Suggested patch:

# Fall back: try python3, then python (Windows), else abort silently
if [ -z "$GRAPHIFY_PYTHON" ]; then
    if command -v python3 >/dev/null 2>&1 && python3 -c "import graphify" 2>/dev/null; then
        GRAPHIFY_PYTHON="python3"
    elif command -v python >/dev/null 2>&1 && python -c "import graphify" 2>/dev/null; then
        GRAPHIFY_PYTHON="python"
    else
        # No usable Python interpreter — hook is a no-op on this machine
        exit 0
    fi
fi

I've been running this patched version locally on a Windows wallnut project since 2026-04-12 without issues. Happy to submit a PR if it's useful.

Environment

  • OS: Windows 11 (build via git-bash shell from Git for Windows)
  • Python: 3.10.11 via python (no python3 symlink)
  • graphify: 0.4.2
  • Shell: bash 5.2 (git-bash MINGW64)

Workaround for affected users

Until a fix lands, patch your local .git/hooks/post-commit and .git/hooks/post-checkout to replace the GRAPHIFY_PYTHON="python3" fallback lines with the cross-platform chain above. The hooks are idempotent so you can re-run graphify hook install anytime (it won't re-overwrite your edits because the patch only touches the fallback branch).

Activity

  1. added a commit that references this issue on Apr 12, 2026
  2. safishamsi commented on Apr 12, 2026

    @safishamsi
    Member

    Fixed in v0.4.3. The interpreter detection now falls back to python (no suffix) after python3 — handles Windows installs that don't ship a python3 shim. If neither has graphify installed the hook exits 0 silently instead of erroring.

  3. added a commit that references this issue on Apr 23, 2026
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