Git Hooks (Husky)
This repository uses Husky to run Git hooks from the root .husky/ directory. Hooks run automatically during commits to keep commit messages, documentation formatting, and Java code style consistent.
Hook scripts live in .husky/ (pre-commit, commit-msg).
Setup
Hooks are configured when you run at the repository root:
npm installThe prepare script runs automatically and points Git at .husky/.
For documentation work, install docs dependencies once:
cd docs && npm installHooks
pre-commit
No-op placeholder. Git always runs pre-commit before commit-msg; the real checks are in commit-msg so the commit subject is validated first.
commit-msg
All checks run in this hook, in fail-fast order:
- Commit message — subject line from the message file Git passes to this hook
- Docs formatting — Prettier check in
docs/when staged files are underdocs/(npm run format:check) - Java code style — Spotless check via Maven when staged
*.javafiles are present
Behavior
- Commit message and docs checks block the commit on failure
- Spotless runs only when Java files are staged; if Maven is not installed locally, Spotless is skipped with a warning
Commit message format (step 1):
type(PROJECT-123): commit message
type(PROJECT): commit messageThe ticket number is optional — use CAPTCHA-123 or just CAPTCHA (uppercase).
Valid types: feat, fix, clean, chore, docs
Valid projects: CAPTCHA, GH
Merge commits
Git’s default merge subjects (for example Merge branch 'main' into feature-branch) are allowed automatically so git merge can finish without renaming the message.
Troubleshooting
Docs formatting fails
cd docs
npm run formatSpotless fails
mvn -f captchaservice-backend/pom.xml spotless:applySkip hooks temporarily
git commit --no-verify -m "chore(CAPTCHA): emergency hotfix"Use sparingly — CI still enforces the same checks.