git-validator-cli
v0.25.0
Published
A simple CLI tool to validate **commits** and **branches** following:
Readme
🚀 git-validator
A simple CLI tool to validate commits and branches following:
It automatically installs a pre-push Git hook that blocks invalid pushes.
Supports custom configuration, detailed error reports, and auto-suggestions for corrections.
📦 Installation
Clone the repository and install dependencies:
git clone https://github.com/danieltinois/git-validator.git
cd git-validator
npm install
npm run build⚡ Usage
1. Install the hook in your repository
Inside the repository you want to protect, run:
npx git-validator initThis will automatically create the .husky/pre-push (if Husky is detected) or .git/hooks/pre-push hook.
2. Run validations manually
You can also validate manually:
# Validate a commit message
npx git-validator commit "feat: add login"
# Validate a branch name
npx git-validator branch "feature/new-feature"✅ Examples
Valid commits
feat: add loginfix(auth): correct password hashingchore: update dependenciesrefactor(api): improve performancedocs: update README
Invalid commits (with auto-suggestions)
fiz: corrigir bug no login
→ 💡 Example:fix: corrigir bug no loginWIP: implementando tela de login
→ 💡 Example:feat: implementando tela de logincorrigir bug no login
→ 💡 Example:feat: corrigir bug no loginfeat: add a very very very very very very very very very very very long message
→ 💡 Example:feat: add a very very very very very very very very very long...
Valid branches
feature/new-featurehotfix/fix-bugrelease/v1.0.0bugfix/minor-adjustmentsupport/legacyfeature/correção-login✅ (supports accents)
Invalid branches (with auto-suggestions)
featuree/login
→ 💡 Example:feature/loginbug/login
→ 💡 Example:bugfix/loginlogin
→ 💡 Example:feature/loginfeature/teste com espaço
→ 💡 Example:feature/teste-com-espaço
⚙️ Configuration
You can customize rules with a .gitvalidatorrc.json file in your project:
{
"commitTypes": ["feat", "fix", "chore", "docs", "refactor"],
"branchPrefixes": ["feature", "hotfix", "release", "bugfix"],
"maxCommitLength": 120
}🔧 Development
Run in dev mode (without build):
npm run dev branch "feature/test"Build:
npm run buildRun tests:
npm run test🌍 Using in other projects
There are two ways to use it in other repositories:
1. Via npx (without global install)
Inside the project you want to protect:
npx git-validator initThis installs the pre-push hook and you’re ready to go 🚀
2. Global installation
If you want to use it in any project without installing locally:
npm install -g git-validatorNow in any repository:
git-validator init🧪 Tests
We use Jest for automated tests.
Examples covered:
- Commit autocorrections (
fiz→fix,fet→feat, etc.) - Blocking WIP/fixup/squash commits
- Branch autocorrections (
featuree/→feature/,bug/→bugfix/) - Unicode support (commits and branches with accents)
Run tests:
yarn jest📌 Roadmap
- [x] Allow configuration via
.gitvalidatorrc - [x] Advanced commit validation (body, footer, BREAKING CHANGE, WIP, etc.)
- [x] Friendly error reports with auto-suggestions
- [x] Branch autocorrection with Unicode support
- [x] Jest automated tests
- [ ] Publish to npm
- [ ] Provide a GitHub Action for CI/CD validation
- [ ] GitLab CI support
- [ ] "fix" mode to auto-correct commits
- [ ] Strict mode (block WIP, fixup, squash, pushes to main)
