Git Hooks
Catch validation errors before they reach the repository by running Repotype in git hooks.
Quick Setup
Section titled “Quick Setup”npx repotype install-checks --hook both --target .This installs both pre-commit and pre-push hooks.
Hook Options
Section titled “Hook Options”| Option | Effect |
|---|---|
--hook pre-commit | Validate before each commit |
--hook pre-push | Validate before pushing |
--hook both | Install both hooks |
Config-Based Installation
Section titled “Config-Based Installation”Define hooks in your config file:
operations: hooks: enabled: true hook: both # pre-commit | pre-push | bothThen apply:
npx repotype apply .What the Hooks Do
Section titled “What the Hooks Do”The installed hooks run:
npx repotype validate . --jsonIf validation fails, the commit/push is blocked with error output.
Manual Hook Scripts
Section titled “Manual Hook Scripts”If you prefer manual control, add to .git/hooks/pre-commit:
#!/bin/shnpx repotype validate . --jsonexit $?Make it executable:
chmod +x .git/hooks/pre-commitIntegration with Husky
Section titled “Integration with Husky”If you use Husky for hook management:
-
Install Husky
Terminal window npm install -D huskynpx husky init -
Add Repotype to pre-commit
Terminal window echo "npx repotype validate ." > .husky/pre-commit
Integration with lint-staged
Section titled “Integration with lint-staged”For faster commits, only validate changed files:
{ "lint-staged": { "*.{ts,tsx}": [ "npx repotype explain" ], "*.md": [ "npx repotype validate" ] }}Bypassing Hooks (Emergency)
Section titled “Bypassing Hooks (Emergency)”In emergencies, you can skip hooks:
git commit --no-verify -m "emergency fix"git push --no-verifyDisabling Hooks
Section titled “Disabling Hooks”Remove hooks from config:
operations: hooks: enabled: falseThen reapply:
npx repotype apply .Or manually remove:
rm .git/hooks/pre-commit .git/hooks/pre-pushTroubleshooting
Section titled “Troubleshooting”Hook not running
Section titled “Hook not running”Check hook is executable:
ls -la .git/hooks/pre-commit# Should show: -rwxr-xr-xHook too slow
Section titled “Hook too slow”Consider:
- Using
pre-pushinstead ofpre-commit - Using
lint-stagedfor file-specific validation - Caching node_modules
Permission denied
Section titled “Permission denied”chmod +x .git/hooks/pre-commitchmod +x .git/hooks/pre-push