Skip to content

xofbd/good-commit-message

Repository files navigation

Python GitHub release License: MIT CI codecov

Commit Message Linter

A simple Python script that checks whether a commit's message follows these conventions:

  1. Sentence capitalization of the first line
  2. The first line does not exceed 50 characters
  3. The first line does not end in a period
  4. A blank line between a commit's first line and the rest of the body
  5. The rest of the lines do not exceed 72 characters
  6. Any lists either use a hyphen (-) or asterisk (*) with hanging indent when the point spans more than one line

These conventions are common and mostly adapted from here

Installation

This project just uses the Python standard library so no 3rd party packages are required for installation. Thus, there is no need for a tool like pipx. However, for development work, it does rely on 3rd party packages.

To install, run:

pip install git+https://github.com/xofbd/good-commit-message.git

or

git clone https://github.com/xofbd/good-commit-message.git
pip install good-commit-message

Note: you can use the --user flag for a local installation as opposed to system-wide.

The installation will add check-commit-message script but you'll need to link it to your project's commit-msg, located in .git/hooks. You can follow the script bin/install-hook or run it (if you've cloned the repo and have not navigated away):

good-commit-message/bin/install-hook <path-to-git-project>

or use curl to fetch and run the script:

curl https://raw.githubusercontent.com/xofbd/good-commit-message/master/bin/install-hook | bash -s <path-to-git-project>

If you are already using commit-msg, you can just edit that file to call check-commit-messsage as part of a larger message checking process.

Usage

With the script linked to your project's commit-msg, the hook is run after creating the commit's message. If a commit message is rejected, you'll be informed on how to retrieve the rejected message so you can edit it and try again and how to skip the check entirely.

License

This project is distributed under the MIT license. Please see LICENSE for more information.