Skip to main content

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 matches type(scope): description, valid type, lowercase start, no trailing period, max 72 chars
  • imperative - First word is an imperative verb (for example add not added)
  • body - Body is present after a blank line
  • signed-off - Signed-off-by: trailer exists
  • signature - Verify GPG or SSH signature

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

Install the hook:

pre-commit install --hook-type commit-msg

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:

  1. A whitelist common commit verbs (add, fix, remove, etc.) that pass immediately without NLP.
  2. nltk POS tagging as a fallback — flags words tagged as past tense (VBD), gerund (VBG), third person (VBZ), etc.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_commit_guard-0.5.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_commit_guard-0.5.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file git_commit_guard-0.5.0.tar.gz.

File metadata

  • Download URL: git_commit_guard-0.5.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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

Hashes for git_commit_guard-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4f732c824c11dd050f1ad8aae77855a6b3217619107e47e057aad65743a1dac3
MD5 18b4e110c656fbba8e19d48ec7735aac
BLAKE2b-256 71707ebb3d6be4c0054f8902ee9d09ede6d266dc1ff110801447cfdfaed5f6cb

See more details on using hashes here.

File details

Details for the file git_commit_guard-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: git_commit_guard-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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

Hashes for git_commit_guard-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7a93e7353da5cc60190e39fdaba5ce400c03cbcfd0ea68e1d0136692ee7fdcc
MD5 6412a656592c9ff2e52efc431cfb8a68
BLAKE2b-256 4d76b97f0066c14fb95337c7808bd4520c18c0741d5ba9a4e8bad863a524d9ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page