Git Hooks¶
This directory contains custom git hooks for the project.
Available Hooks¶
commit-msg¶
Enforces conventional commit message format before allowing the commit.
Features:
- Validates commit messages follow conventional commit format
- Provides helpful error messages with examples
- Allows merge and revert commits
- Prevents commits with invalid format
Supported commit types:
feat:→ New feature (added to CHANGELOG)fix:→ Bug fix (added to CHANGELOG)docs:→ Documentation changes (added to CHANGELOG)refactor:→ Code refactoring (added to CHANGELOG)perf:→ Performance improvements (added to CHANGELOG)test:→ Test-related changeschore:→ Maintenance tasksstyle:→ Code style/formattingci:→ CI/CD changesbuild:→ Build system changesrevert:→ Revert previous commits
post-commit¶
Automatically updates CHANGELOG.md with commit messages following conventional commit format.
Features:
- Parses conventional commit messages
- Adds entries to appropriate sections in
[Unreleased] - Amends the commit to include CHANGELOG updates
- Avoids infinite loops
- Skips non-conventional commits
Types added to CHANGELOG: feat, fix, docs, refactor, perf
Types skipped: test, chore, style, ci, build, revert
Installation¶
Option 1: Using Task (Recommended)¶
Option 2: Manual Installation¶
# Configure git to use this hooks directory
git config core.hooksPath .githooks
# Make hooks executable
chmod +x .githooks/*
Option 3: Symlink (Alternative)¶
# Link individual hooks
ln -sf ../../.githooks/post-commit .git/hooks/post-commit
chmod +x .git/hooks/post-commit
Disabling Hooks¶
Temporarily (for one commit)¶
Permanently¶
# Revert to default hooks directory
git config --unset core.hooksPath
# Or remove symlinks
rm .git/hooks/post-commit
Testing Hooks¶
Test the post-commit hook:
# Make a test commit
echo "test" >> test.txt
git add test.txt
git commit -m "feat: add test feature"
# Check if CHANGELOG.md was updated
git log -1 --stat
Troubleshooting¶
Hook not running¶
- Check if hooks are executable:
- Verify git configuration:
- Check for errors:
CHANGELOG not updating¶
- Ensure CHANGELOG.md exists
- Verify
[Unreleased]section exists - Check that appropriate subsections exist (
### Added,### Fixed, etc.) - Use conventional commit format:
type: description
Hook Behavior¶
commit-msg Hook¶
Runs before the commit is created:
- ✅ Validates commit message format
- ✅ Checks against allowed types
- ✅ Rejects invalid messages with helpful error
- ✅ Allows merge and revert commits
- ✅ Prevents commits with bad format
Example:
# Invalid commit - rejected
git commit -m "added new feature"
# ❌ ERROR: Commit message does not follow conventional commit format!
# Valid commit - accepted
git commit -m "feat: add new feature"
# ✅ Commit created
post-commit Hook¶
Runs after the commit is created:
- ✅ Parses the commit message
- ✅ Determines the appropriate CHANGELOG section
- ✅ Adds an entry with commit hash
- ✅ Amends the commit to include CHANGELOG
- ✅ Prevents infinite loops
- ✅ Skips non-conventional commits
Example:
# Commit message
git commit -m "feat: add auto-completion support"
# CHANGELOG.md entry added automatically
### Added
- add auto-completion support (a1b2c3d)
Notes¶
- The hook uses
--amendto include CHANGELOG in the same commit - This means the commit hash in CHANGELOG may differ slightly
- The hook is safe and won't break your commits
- You can always edit CHANGELOG.md manually if needed