Automated commit validation and pre-commit checks
This document explains how to set up and use git hooks for the Resonance project.
When you clone and set up the project:
# Clone repository
git clone https://github.com/matpdev/resonance.git
cd resonance
# Install dependencies
flutter pub get
# Install Node.js dependencies (for git hooks)
npm install
# Install git hooks
npx husky install
# Make hooks executable
chmod +x .husky/*# Check husky installation
npx husky install
# Should output:
# husky - Git hooks installedRuns before creating a commit:
✅ Flutter analyze - Code quality checks
✅ Dart format check - Code formatting validation
✅ Tests (optional) - Run unit testsStops commit if:
- Analysis fails
- Code formatting issues detected
- Tests fail (if enabled)
Validates commit message format:
✅ Checks type (feat, fix, docs, etc.)
✅ Validates scope (dashboard, headers, etc.)
✅ Enforces subject line format (max 50 chars)
✅ Checks for body/footer rulesStops commit if:
- Message doesn't follow conventional commits format
- Subject exceeds 50 characters
- Invalid type or scope
# 1. Make changes to your code
# 2. Stage changes
git add .
# 3. Attempt to commit
git commit -m "feat(dashboard): add request history"
# Hooks automatically run:
# ✅ Pre-commit: Flutter analysis
# ✅ Commit-msg: Message validation
# ✅ If all pass: Commit created ✨git commit
↓
pre-commit hook runs
├─ flutter analyze
└─ Check code formatting
↓ (if passes)
commit-msg hook runs
├─ Validate message format
├─ Check type, scope, subject
└─ Verify body/footer rules
↓ (if passes)
✅ Commit created!
$ git commit -m "feat: add something"
🔍 Running Flutter analysis before commit...
❌ Flutter analysis failed. Commit aborted.
Error: file.dart:45 - Strong mode issueSolution:
# Fix the analysis issue
flutter analyze # See detailed error
# Edit the file to fix issue
git add .
git commit -m "feat: add something" # Try again$ git commit -m "added new feature"
⧗ input: added new feature
✖ subject must not be in past tense [subject-case]
✖ type must be lowercase [type-case]
commit message validation failedSolution:
# Fix the message format
git commit --amend -m "feat: add new feature"$ git commit -m "feat: add feature"
❌ Code formatting issues found:
file.dart: Fix formatting
flutter format . # Auto-format
git add .
git commit -m "feat: add feature" # Try againIf absolutely necessary:
# Skip all hooks
git commit --no-verify -m "feat: emergency fix"
# Or skip pre-commit only
HUSKY=0 git commit -m "feat: emergency fix"Consequences:
- 🔴 CI/CD pipeline may fail
- 🔴 Code quality standards ignored
- 🔴 History consistency broken
# Let hooks guide you
git commit -m "feat: add feature" # Fails
# Follow instructions and fix
flutter analyze
flutter format .
# Then commit properly
git add .
git commit -m "feat: add feature" # Passes!Enforces:
- Valid types:
feat,fix,docs,style,refactor,perf,test,chore,ci,revert - Valid scopes:
dashboard,headers,body,response,context,theme,utils,models,config - Subject: Max 50 chars, imperative mood, no period
- Body: Wrapped at 100 chars, optional but detailed
- Footer: Issue references, breaking changes
Runs Flutter checks:
flutter analyze- Code quality- Optional:
flutter format --check- Code formatting - Optional:
flutter test- Test suite
Validates using commitlint:
- Message structure
- Type validation
- Scope validation
- Subject line format
- Body/footer format
# Reinstall husky
rm -rf .husky node_modules
npm install
npx husky install
chmod +x .husky/*# Check if husky is initialized
test -d .husky && echo "✅ Husky initialized" || echo "❌ Not initialized"
# Make sure .husky scripts are executable
ls -la .husky/
# They should show:
# -rwxr-xr-x commit-msg
# -rwxr-xr-x pre-commit# Install commitlint locally
npm install -D commitlint @commitlint/config-conventional
# Or install globally
npm install -g commitlint @commitlint/config-conventional# Make sure git hooks are executable
chmod +x .husky/pre-commit
chmod +x .husky/commit-msg
# Try running hook manually
./.husky/pre-commit
./.husky/commit-msg# Run as administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Or use Git Bash instead of PowerShell- GIT_COMMITS.md - Detailed commit conventions
- CONTRIBUTING.md - Full contribution guidelines
- Husky Documentation
- commitlint Documentation
- Conventional Commits
- Cloned repository
- Ran
npm install - Ran
npx husky install - Made
.husky/*executable - Read
GIT_COMMITS.md - Tested first commit
- Understand hook workflow
- Know how to bypass (and when NOT to!)
feat(scope): description
├─ feat = Type (what kind of change)
├─ (scope) = Part of code affected
└─ description = What was changed
Your commit → pre-commit hook → commit-msg hook → ✅ Commit stored
↓ ↓
Check code Check message format
✅ Passes ✅ Passes
Automated quality checks ensure consistency! ✨