chore(githooks): Add pre-commit hook allowing two staged paths

Ship a tracked hook that rejects more than two staged paths so commits stay
small while still allowing tightly coupled pairs.

- Activate with: git config core.hooksPath .githooks (from repo root)
This commit is contained in:
Jukka Aho
2026-05-09 16:12:58 +03:00
parent 52dbf26d62
commit 86a2021c92
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# Pre-commit hook: prefer small commits; allow at most two staged paths.
# Enable with: git config core.hooksPath .githooks
staged_files=$(git diff --cached --name-only)
file_count=$(echo "$staged_files" | grep -v '^$' | wc -l | tr -d ' ')
if [ "$file_count" -gt 2 ]; then
echo "❌ COMMIT PROTOCOL VIOLATION: Attempting to commit $file_count files (maximum 2)"
echo ""
echo "Prefer tiny commits; combining more than two paths needs splitting or a hook bypass."
echo ""
echo "Staged files:"
echo "$staged_files"
echo ""
echo "See .github/prompts/commit.prompt.md"
exit 1
fi
if [ "$file_count" -eq 2 ]; then
echo "✅ Committing two files:"
echo "$staged_files"
exit 0
fi
if [ "$file_count" -eq 1 ]; then
echo "✅ Committing single file: $(echo "$staged_files" | head -1)"
exit 0
fi
echo "⚠️ No files staged for commit"
exit 1