Skip to content

Git hooks can never resolve the interpreter when Python is under a path with a space (Windows) #2581

Open

Description

@carnaclin

Version: graphifyy 0.8.49, Windows 11, Git for Windows

Symptom

Every commit and checkout prints:

[graphify hook] could not locate a Python with graphify installed. Add the graphify bin dir to
PATH or re-run 'graphify hook install' from the env where graphify lives.

graphify hook install does not fix it — the regenerated hook has the same defect, and
graphify update . from the same shell works fine.

Cause

graphify-out/.graphify_python correctly contains C:\Program Files\Python313\python.exe, but
all four probes in the generated hook fail on it:

  1. _PINNED is emitted as _PINNED='' by hook install — never populated, so the probe
    documented as "tried first so the hook works even when the graphify launcher is not on PATH"
    is dead.

  2. .graphify_python is read with

    _FROM_FILE=$(cat "$_GFY_PYTHON_FILE" 2>/dev/null | tr -d '[:space:]')

    tr -d '[:space:]' deletes interior whitespace, so the path becomes
    C:\ProgramFiles\Python313\python.exe — which does not exist. It should trim leading and
    trailing whitespace only. The file is also written with a UTF-8 BOM, which survives the tr
    and corrupts the first path character.

    Even with that fixed, the allowlist immediately after rejects the value: the character class
    *[!a-zA-Z0-9/_.@:\-]* excludes both the backslash and the space, so no native Windows path
    can pass it.

  3. Shebang probe — command -v graphify returns graphify.exe, and the hook explicitly sets
    _SHEBANG="" for *.exe, so this yields nothing on Windows by design.

  4. python / python3 fallback — resolves to whatever is first on PATH, commonly a project
    venv or the WindowsApps stub, neither of which has graphify importable.

Reproduce the second probe directly:

$ _F=$(cat graphify-out/.graphify_python | tr -d '[:space:]'); echo "[$_F]"
[C:\ProgramFiles\Python313\python.exe]      # note the lost space
$ case "$_F" in *[!a-zA-Z0-9/_.@:\-]*) echo REJECTED ;; esac
REJECTED

Suggested fixes

  • Trim only leading/trailing whitespace when reading .graphify_python, and strip a BOM.
  • Write .graphify_python without a BOM.
  • Populate _PINNED at hook install time with sys.executable — this is the one probe that
    works regardless of PATH, and it is already quoted in the hook, so spaces are harmless.
  • Widen or drop the allowlist for paths that come from the pin/pointer file rather than from a
    parsed shebang. A backslash and a space are ordinary characters in a Windows path.

Workaround

Setting _PINNED='/c/Program Files/Python313/python.exe' by hand in .git/hooks/post-commit and
.git/hooks/post-checkout makes both hooks work immediately — the pin probe quotes the value, so
the space is fine. It is lost on the next hook install.

Activity

  1. sde-melo commented on Aug 18, 2026

    @sde-melo

    Same failure on graphifyy 0.9.46 (Windows 11, Git for Windows, uv tool install "graphifyy[terraform]"), with one more angle: the home directory contains non-ASCII characters as well as spaces (C:\Users\Sébastien de Melo\...), so the .graphify_python allowlist *[!a-zA-Z0-9/_.@:\-]* rejects the interpreter path twice over — and, as #2852 describes, the command -v graphify probe cannot help because the uv shim in ~/.local/bin has no python.exe beside it and no parsable shebang. Result: every commit prints could not locate a Python with graphify installed, even right after graphify hook install run from the tool's own environment (_PINNED='' is emitted empty here too).

    Workaround that works, for anyone stuck on this: create an ASCII-only junction to uv's tool directory and point the pin file at it —

    mklink /J C:\Users\Public\uv-tools "%APPDATA%\uv\tools"
    echo C:/Users/Public/uv-tools/graphifyy/Scripts/python.exe > graphify-out/.graphify_python
    

    (forward slashes, no BOM, no trailing whitespace; the file is machine-specific so it belongs in .gitignore). After that the post-commit hook launches the background rebuild normally.

    Suggested fixes, in order of bang for the buck: (1) let an environment variable (GRAPHIFY_PYTHON) or the pinned _PINNED value bypass the allowlist entirely — the allowlist is meant to stop injection, and a -x check on the resolved path already does that job; (2) trim only leading/trailing whitespace instead of tr -d '[:space:]'; (3) accept spaces, backslashes and non-ASCII letters in the allowlist (Windows user profiles are routinely Firstname Lastname with accents).

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