Skip to content

fix(hooks): find the policy hooks from any install path - #10

Merged
koryei merged 6 commits into
mainfrom
fix/dispatcher-finds-policy-hooks
Nov 27, 2026
Merged

koryei merged 6 commits into
mainfrom
fix/dispatcher-finds-policy-hooks

Conversation

@koryei

@koryei koryei commented Nov 27, 2026

Copy link
Copy Markdown
Owner

The bug

hooks/_dispatch hardcoded $HOME/.config/git-policy/hooks/$name. Clone the
repo anywhere else, run ./install.sh, and it printed:

✓ installed the hook dispatcher
✓ set core.hooksPath to ~/.git-hooks

…while every hook was dead. A commit on main went straight through.

Worse, rules check then reported hooks ✓ 3/3 active and All checks passed.
It grepped the dispatcher for the string git-policy/hooks, which is present
whether or not that path exists. A false green on the one thing the tool exists
to enforce.

The fix

The installer records the real hooks directory in ~/.git-hooks/_policy and the
dispatcher reads it, falling back to the documented path when the file is
absent — so the template still works on its own, and existing installs at the
documented path keep working.

hook_active now resolves the directory the dispatcher actually reads and
requires an executable policy hook there, so a stale pointer reports 0/3 and
exits 1.

A dispatcher from before _policy cannot be repointed, so it is replaced and
the installer says so, asking for local edits to be re-added.

Commits

Each one is a single concern:

Commit What
fix(hooks) dispatcher reads _policy; installer writes it and upgrades old dispatchers
fix(rules) health check verifies reachability instead of grepping a string
feat(rules) rules hooks shows the resolved POLICY path
test 8 new cases, 5 of which fail on the previous code
docs how-it-works.md shows the real lookup
docs(install) corrects a comment that stopped being true

How to verify

./test/install.sh   # 26 passed (was 18)
./test/run.sh       # 10 passed

The new cases fail on main: I ran the updated suite against the pre-fix
hooks/_dispatch, install.sh and bin/rules and got 21 passed, 5 failed,
including hooks fire from another install path (want 1, got 0) — a commit on
main is now actually refused after an off-path install.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe vibe@mistral.ai

koryei and others added 6 commits November 26, 2026 22:41
The dispatcher hardcoded ~/.config/git-policy/hooks, so a clone anywhere
else installed hooks that never fired while the installer still printed
"installed the hook dispatcher" and "set core.hooksPath". A commit on
main then went through.

The installer now records the real hooks directory in ~/.git-hooks/_policy
and the dispatcher reads it, falling back to the documented path when the
file is absent so the template still works on its own.

A dispatcher that predates _policy is replaced, since it cannot be
repointed; the installer says so and asks for local edits to be re-added.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
hook_active grepped the dispatcher for the string 'git-policy/hooks',
which is present whether or not that path exists. So `rules check`
reported "hooks 3/3 active" and "All checks passed" while the hooks were
dead, which is the one thing the tool exists to catch.

It now resolves the directory the dispatcher actually reads from _policy
and requires an executable policy hook there. A stale pointer reports
0/3 active and exits 1.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
When hooks are inactive the cause is usually that the dispatcher looks in
a directory the policy hooks are not in. `rules hooks` showed DISPATCH and
HOOKSPATH but not the resolved policy directory, so that mismatch was
invisible.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Nothing tested a clone outside ~/.config/git-policy, which is why the
dispatcher bug went unnoticed, and `rules check` reported a false green
that hid it.

Five cases fail on the previous code: the recorded hooks directory, a
commit on main actually being refused after an off-path install, a stale
pointer reading as inactive, the health check exiting 1 for it, and an
old dispatcher being replaced.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
The page showed the hardcoded ~/.config/git-policy path, which is what the
dispatcher no longer does. It now shows the _policy lookup and says why the
file exists.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
The section header still said a customised dispatcher is never replaced,
which stopped being true when an old one started being swapped out.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@koryei
koryei force-pushed the fix/dispatcher-finds-policy-hooks branch from b1d3f89 to 465104d Compare November 27, 2026 03:41
@koryei
koryei merged commit 191975c into main Nov 27, 2026
1 check passed
@koryei
koryei deleted the fix/dispatcher-finds-policy-hooks branch November 27, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant