majorwiki/.githooks/pre-commit
Marcus Summers 7e422ee332 githooks: mark pre-commit executable
The pre-commit hook (which enforces SUMMARY.md links for new articles)
was tracked at mode 100644, so even with `core.hooksPath=.githooks`
configured, git silently skipped it. Bump tracked mode to 100755 so
fresh clones get the working hook without a manual chmod step.

Discovered while installing the wiki-commit/hooks setup on MajorMac.
No content change; .githooks/ is outside the MkDocs source so this
will not alter the rendered notes.majorshouse.com site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 09:42:06 -04:00

36 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# pre-commit — fail if a newly-added article is not linked from SUMMARY.md.
# Bypass with `git commit --no-verify` if you genuinely need to.
set -euo pipefail
# Articles being added or renamed in this commit (excludes meta/index/README/SUMMARY/MajorWiki-Deploy-Status, and any */index.md).
added=$(git diff --cached --name-only --diff-filter=AR -- '*.md' \
| grep -vE '^(README|index|SUMMARY|MajorWiki-Deploy-Status)\.md$|/index\.md$' \
|| true)
[ -z "$added" ] && exit 0
# Read the staged SUMMARY.md if it's part of the commit; otherwise the working-tree copy.
if git diff --cached --name-only | grep -q '^SUMMARY\.md$'; then
summary=$(git show :SUMMARY.md)
else
summary=$(cat SUMMARY.md)
fi
missing=()
while IFS= read -r article; do
[ -z "$article" ] && continue
if ! grep -qF -- "$article" <<<"$summary"; then
missing+=("$article")
fi
done <<<"$added"
if [ ${#missing[@]} -gt 0 ]; then
echo "✗ pre-commit: new article(s) not linked from SUMMARY.md:" >&2
printf ' %s\n' "${missing[@]}" >&2
echo "" >&2
echo "Add a SUMMARY.md entry for each, or use 'git commit --no-verify' to bypass." >&2
exit 1
fi
exit 0