Git Hooks with Lefthook
View SourceThis project uses Lefthook to manage git hooks. This ensures all developers have the same hooks configured automatically.
Installation
Run the setup script after cloning the repository:
./scripts/setup-dev.sh
This will:
- Install Lefthook (if not already installed)
- Install git hooks from
lefthook.yml - Configure the pre-commit hook
Hooks Configuration
Pre-commit Hook
Location: pre-commit.sh (root of repository)
Behavior:
- Runs
mix format - Re-stages any already-staged
.ex/.exsfiles that were reformatted
Skip the hook:
git commit --no-verify
Manual Lefthook Commands
# Install/reinstall hooks
lefthook install
# Run all hooks manually
lefthook run pre-commit
# Uninstall hooks
lefthook uninstall
Configuration File
The lefthook.yml file in the root defines all hooks. Edit this file to modify hook behavior.
Example:
pre-commit:
commands:
format:
run: bash pre-commit.sh
stage_fixed: trueTroubleshooting
Lefthook not found
Re-run the setup script:
./scripts/setup-dev.sh
Hooks not running
Reinstall hooks:
lefthook install
Want to disable hooks temporarily
Use --no-verify:
git commit --no-verify -m "your message"
Why Lefthook?
- Versionable: Hooks are tracked in git, not in
.git/hooks/ - Cross-platform: Works on macOS, Linux, Windows
- Fast: Written in Go, parallel execution
- Simple: YAML configuration, no complex scripts
- Team-friendly: Everyone gets the same hooks automatically