From b09d7caf4dc37ab340b575fc3d073dafd1709520 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 1 Oct 2026 17:57:36 +0000 Subject: [PATCH] script/install-precommit: ask git where hooks live (closes #129) The script wrote the hook to .git/hooks, which fails when .git is a file rather than a directory, as in a clone made with --separate-git-dir. It now asks git for the hooks directory with `git rev-parse --git-path hooks` and creates it if missing. In an ordinary clone git answers .git/hooks, so nothing moves there. Where core.hooksPath is set, git answers that directory, so the hook now lands where git runs it instead of in .git/hooks, where it never ran. Model: opus-5-5 --- TODO.md | 2 ++ script/install-precommit | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 5f654fe..34c2014 100644 --- a/TODO.md +++ b/TODO.md @@ -19,6 +19,8 @@ Rationale, Design, TODO, License, Author) if any are still missing. # Completed Steps +- 2026-10-01: `script/install-precommit` asks git where hooks live, so + `make hooks` also works where `.git` is a file (closes #129). - 2026-09-29: the live-DNS test package is renamed `internal/livednstest` and added to the `test-support` `deny` list in `.golangci.yml`, so `make lint` fails when program code imports it (closes #164). diff --git a/script/install-precommit b/script/install-precommit index 723bae1..7ebebf2 100755 --- a/script/install-precommit +++ b/script/install-precommit @@ -7,7 +7,11 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" main() { cd "$ROOT" - hook=".git/hooks/pre-commit" + # Ask git where hooks live: .git is a file, not a directory, in some + # checkouts (for example a clone made with --separate-git-dir). + hooks="$(git rev-parse --git-path hooks)" + mkdir -p "$hooks" + hook="$hooks/pre-commit" printf '#!/bin/sh\nset -e\nscript/precommit\n' > "$hook" chmod +x "$hook" echo "pre-commit hook installed: runs script/precommit"