diff --git a/TODO.md b/TODO.md index 23a1f8f..bf44a06 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 for the repository's git + directory, so `make hooks` also works where `.git` is a file (closes #129). - 2026-10-01: wildcard CORS now applies only to the public routes, not to `/metrics`, and allows only the methods they serve (closes #100). - 2026-10-01: `internal/state` and `internal/watcher` no longer export test-only diff --git a/script/install-precommit b/script/install-precommit index 723bae1..c005c5e 100755 --- a/script/install-precommit +++ b/script/install-precommit @@ -7,7 +7,20 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" main() { cd "$ROOT" - hook=".git/hooks/pre-commit" + # Stop if this directory is not the top of its own git checkout, for + # example a copy inside another repository, whose hook must not be + # replaced. + if [ "$(git rev-parse --show-toplevel)" != "$ROOT" ]; then + echo "install-precommit: $ROOT is not the top of a git checkout" >&2 + exit 1 + fi + # Ask git for the repository's own git directory: .git is a file, not + # a directory, in some checkouts (for example a clone made with + # --separate-git-dir). core.hooksPath is deliberately not followed, so + # the hook is never written outside this repository. + hooks="$(git rev-parse --git-common-dir)/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"