Opinionated conventional commit message linter with imperative mood detection
Project description
commit-guard
Opinionated conventional commit message linter with imperative mood detection.
Unlike regular expression only tools, commit-guard uses NLP (nltk POS tagging) to verify that commit descriptions start with an imperative verb.
Example
$ commit-guard
✗ subject does not match 'type(scope): description':
Merge pull request #5 from fix/branch
✗ missing 'Signed-off-by' trailer
✗ commit is not signed (GPG/SSH)
Installation
From PyPI:
uv tool install git-commit-guard
or:
pipx install git-commit-guard
From a local clone:
uv tool install -e .
During development:
uv run commit-guard
Usage
# check HEAD
commit-guard
# check specific commit
commit-guard abc1234
# check commit message file (for git hooks)
commit-guard --message-file .git/COMMIT_EDITMSG
# pipe message via stdin
echo "fix(auth): add token refresh" | commit-guard
Selecting checks
All checks run by default. Use --enable or --disable with
comma-separated values:
# only check subject format and imperative mood
commit-guard --enable subject,imperative
# skip body and signature checks
commit-guard --disable body,signed-off,signature
Available checks:
subject- Format matchestype(scope): description, valid type, lowercase start, no trailing period, max 72 charsimperative- First word is an imperative verb (for exampleaddnotadded)body- Body is present after a blank linesigned-off-Signed-off-by:trailer existssignature- Verify GPG or SSH signature
Scope validation
By default any scope is accepted and scope is optional. Use --scopes to
restrict allowed values and --require-scope to enforce that a scope is always
present:
# only allow known scopes
commit-guard --scopes auth,api,db
# require a scope
commit-guard --require-scope
# combine both
commit-guard --scopes auth,api --require-scope
Configuration file
Place .commit-guard.toml in your project root (or any parent directory) to
set defaults for enable, disable, scopes, and require-scope.
commit-guard searches upward from the working directory and uses the first file
found.
# .commit-guard.toml
disable = ["signature", "body"]
scopes = ["auth", "api", "db"]
require-scope = true
# .commit-guard.toml
enable = ["subject", "imperative"]
CLI flags (--enable, --disable, --scopes, --require-scope) take full
precedence and ignore config file values when provided.
Checking a range of commits
# all non-merge commits between tags
git rev-list --no-merges v1.0..v2.0 | while read -r rev; do
commit-guard "$rev" || git log -1 --oneline "$rev"
done
# only subject checks on a PR range
git rev-list --no-merges origin/main..HEAD | while read -r rev; do
commit-guard "$rev" --enable subject,imperative
done
pre-commit
Add to your .pre-commit-config.yaml:
---
repos:
- repo: https://github.com/benner/commit-guard
rev: v0.1.0
hooks:
- id: commit-guard
- id: commit-guard-signature
Install the hooks:
pre-commit install --hook-type commit-msg --hook-type post-commit
commit-guard runs at the commit-msg stage and checks message format.
commit-guard-signature runs at the post-commit stage and verifies
the GPG/SSH signature after the commit object is created.
To selectively enable or disable checks, pass args:
- id: commit-guard
args: ["--enable", "subject,imperative"]
Imperative mood detection
commit-guard combines two strategies to detect non-imperative descriptions:
- nltk POS tagging — flags words tagged as past tense (
VBD), gerund (VBG), third person (VBZ), etc. - WordNet morphology as a fallback for words the tagger misclassifies.
This catches common mistakes like added logging or fixes bug while
keeping false positives low.
Conventional commit format
type(scope): description
body
trailers
Supported types: feat, fix, docs, style, refactor, perf, test,
build, ci, chore, revert.
Scope is optional. Mark breaking changes with ! before
the colon.
License
GPLv2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_commit_guard-0.8.0.tar.gz.
File metadata
- Download URL: git_commit_guard-0.8.0.tar.gz
- Upload date:
- Size: 67.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3f64718c0d20754e75f26f2bcf8ce35a4fd8ff6f55d882548234ece52fe3f54
|
|
| MD5 |
43314157eb827ec3d13bd14dd4c96b56
|
|
| BLAKE2b-256 |
4a79b37eae53871067e1925d0a8bbe042daf7031351b0c95ef3a6a3717f7db1a
|
File details
Details for the file git_commit_guard-0.8.0-py3-none-any.whl.
File metadata
- Download URL: git_commit_guard-0.8.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61681ff256453d318e1d6d12911c698a57d726419c4826dc13d337c0d11e9f47
|
|
| MD5 |
8572f637bfaffda4e26936303abc8bf2
|
|
| BLAKE2b-256 |
620c954c0bf4c5be816b8ea519eec657c853f4bc77a40386172317e522702912
|