A simple Python script that checks whether a commit's message follows these conventions:
- Sentence capitalization of the first line
- The first line does not exceed 50 characters
- The first line does not end in a period
- A blank line between a commit's first line and the rest of the body
- The rest of the lines do not exceed 72 characters
- 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
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.
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.
This project is distributed under the MIT license. Please see LICENSE
for more information.