A pre-commit hook that checks commit messages for Conventional Commits formatting.
Actively maintained. Last release 5 weeks ago, commits in 9 of the last 26 weeks. A safe choice.
pip install conventional-pre-commitconventional-pre-commit
A pre-commit hook to check commit messages for
Conventional Commits formatting.
Works with Python >= 3.8.
Usage
Make sure pre-commit is installed.
Create a blank configuration file at the root of your repo, if needed:
touch .pre-commit-config.yaml
Add/update default_install_hook_types and add a new repo entry in your configuration file:
default_install_hook_types:
- pre-commit
- commit-msg
repos:
# - repo: ...
- repo: https://github.com/compilerla/conventional-pre-commit
rev: <git sha or tag>
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: []
Install the pre-commit script:
pre-commit install --install-hooks
Make a (normal) commit :x::
$ git commit -m "add a new feature"
[INFO] Initializing environment for ....
Conventional Commit......................................................Failed
- hook id: conventional-pre-commit
- duration: 0.07s
- exit code: 1
[Bad commit message] >> add a new feature
Your commit message does not follow Conventional Commits formatting
https://www.conventionalcommits.org/
And with the --verbose arg:
$ git commit -m "add a new feature"
[INFO] Initializing environment for ....
Conventional Commit......................................................Failed
- hook id: conventional-pre-commit
- duration: 0.07s
- exit code: 1
[Bad commit message] >> add a new feature
Your commit message does not follow Conventional Commits formatting
https://www.conventionalcommits.org/
Conventional Commit messages follow a pattern like:
type(scope): subject
extended body
Please correct the following errors:
- Expected value for type from: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
Run:
git commit --edit --file=.git/COMMIT_EDITMSG
to edit the commit message and retry the commit.
Make a (conventional) commit :heavy_check_mark::
$ git commit -m "feat: add a new feature"
[INFO] Initializing environment for ....
Conventional Commit......................................................Passed
- hook id: conventional-pre-commit
- duration: 0.05s