Skip to content

hook install writes a machine-specific interpreter path into tracked .githooks files, and mangles non-ASCII in its templates on Windows #2989

Open

Description

@egarcia74

Two separate defects in graphify hook install, both making its output unsafe to commit. Filed
together because they share a cause (the hook-template writer) and are hit by the same command.

Defect 1 — machine-specific _PINNED path written into TRACKED files

hook install writes the running machine's interpreter into .githooks/post-commit and
.githooks/post-checkout:

_PINNED='/Users/someone/.local/pipx/venvs/graphifyy/bin/python'

Those files are tracked (that is the point of core.hooksPath), so on a second machine the same
command rewrites the line:

-_PINNED='/Users/someone/.local/pipx/venvs/graphifyy/bin/python'
+_PINNED='C:\Users\Someone\AppData\Roaming\uv\tools\graphifyy\Scripts\python.exe'

Each machine now overwrites the other's pin on every install — permanent ping-pong churn on a
functional file, and a guaranteed conflict if both do it before syncing.

It also appears unnecessary. The hook already resolves the interpreter through
graphify-out/.graphify_python (gitignored, written automatically) and then a PATH probe. On the
Windows machine above, _PINNED pointed at a nonexistent macOS path and the hook worked correctly
via that fallback the whole time.

Suggested fix

Prefer the gitignored per-machine file as the primary mechanism and stop writing an absolute path
into the tracked template — or write _PINNED='' and let the existing probe chain resolve it. If
pinning must stay, put it in a gitignored sidecar the tracked hook sources.

Defect 2 — non-ASCII in hook templates is corrupted on Windows

On Windows, hook install writes an em-dash in its own comment as three mojibake characters:

-# branch switch but leaves the tree unchanged - nothing to rebuild (#2421).
+# branch switch but leaves the tree unchanged <mojibake> nothing to rebuild (#2421).

Byte-level, the written file contains CE 93 C3 87 C3 B6 where a UTF-8 em-dash (E2 80 94) was
expected. That is U+0393 U+00C7 U+00F6 — the em-dash's UTF-8 bytes decoded as cp437 and then
re-encoded as UTF-8. Classic double-decode: somewhere the template is read or written using the
console/ANSI codepage instead of UTF-8.

Functionally harmless here (it is inside a # comment), but:

  • it corrupts the file's content silently, and
  • it is a second churn source, because macOS writes the correct em-dash and Windows writes the
    mojibake, so the two flip-flop.

Reproduce

graphify hook install          # on macOS, commit the result
# then on Windows:
graphify hook install
git diff -- .githooks/         # shows both the _PINNED flip and the mangled em-dash

Suggested fix

Read and write the hook templates with an explicit encoding="utf-8" (and newline="" where
relevant). Note _register_merge_driver in hooks.py already does this correctly for
.gitattributes — attrs.write_text(..., encoding="utf-8", newline="\n") — so the fix is to make
the hook-script writer consistent with it.

Workaround in use

Run hook install, then discard the file changes and keep only the config:

graphify hook install
graphify hook status            # confirm "merge driver: registered"
git checkout -- .githooks/      # discard machine-specific + mangled edits

Discarding the files does not undo the merge-driver registration, which lives in local git config.
This is worth calling out in the README regardless of the fixes, since hook install's output is
currently not safe to commit.

Related

graphify hook status was invaluable in diagnosing a third issue: it correctly reported
partially registered (.gitattributes line set, git config missing) on a fresh clone, because the
.gitattributes line is committed by whoever ran hook install first while the driver it names
lives in per-clone local config. Worth emphasising in the README that a clone which skips
hook install has a merge driver named but not defined, so Git silently falls back to a normal
merge and graph.json can still get conflict markers — the failure is invisible unless you run
hook status.

Environment

  • graphify 0.9.49 (installed from fork tag v0.9.49-tsql.2; fork changes are confined to SQL
    extraction/packaging, so these paths are unmodified upstream)
  • Windows Server 2022 (PowerShell 7.6.5, Git 2.53) and macOS

Activity

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