Skip to main content

A set of tools to validate git Conventional Commit messages.

Project description

Commit Message Git Hook

A set of tools to validate git Conventional Commit messages.

See the Conventional Commits Specification.

NOTE: It doesn't affect any previous commit on your repository.

Installation Instructions

Install from PyPI (Python Package Index)

Run the script below to install the latest version of this package:

pip install commit-msg-git-hook --upgrade

Setup the Local Git Hook commit-msg

Run one of the scripts below to scaffold the hook:

  • For Linux and macOS:
python3 -m commit_msg_git_hook.setup
  • For Windows:
python -m commit_msg_git_hook.setup

It does the following steps:

  • Reads and then shows the type of your Operating System.
    • Exits with an error message if the OS is unsupported.
  • Creates a directory for git-hooks, by default ./.github/git-hooks.
    • Creates subdirectories for each of the supported OS's.
    • Creates the commit-msg hook file for each OS if it doesn't exist.
      • Fills it with a basic script to call commit_msg.main(), from this package.
      • If the OS is Linux or macOS, makes the hook file executable.
  • Sets the hooks (relative) path to the current repository as the directory respective to the OS type (for example: ./.github/git-hooks/linux).
  • Creates a configuration file commit-msg.config.json if it doesn't exist.
  • Ends with a success message referencing again the type of your OS.

Configuration Instructions

Customize the configuration file commit-msg.config.json to fit your project's needs.

Probably you will want to add scopes, to fully utilize the Conventional Commits Specification.

Basic Usage

After setting up and adding the new files to your git remote repository, your collaborators will need to run the installation and setup steps again. But, this time, the setup will only set the hooks path and make sure the file commit-msg is executable.

Every time you make a commit, the hook will check if its message is in accordance to the specification and the project's customization.

How To Edit Commits

If your branch is not shared yet (not merged into develop, for example), you can edit your commits with the command below. Git will list the last n commits and ask you whether you want to keep or edit each one of them.

git rebase -i HEAD~n

More information here: https://docs.github.com/pt/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message

Credits

This package was created from a Craicoverflow tutorial.

See the tutorial at the link: https://dev.to/craicoverflow/enforcing-conventional-commits-using-git-hooks-1o5p

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

commit_msg_git_hook-0.5.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

commit_msg_git_hook-0.5.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file commit_msg_git_hook-0.5.1.tar.gz.

File metadata

  • Download URL: commit_msg_git_hook-0.5.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for commit_msg_git_hook-0.5.1.tar.gz
Algorithm Hash digest
SHA256 c52057ac40b5b9895aae5cdb62aaf14a9aac803d00d1062c1b49e6df2a2756ed
MD5 6bd57922b1087c7557d5d6ba5639e95d
BLAKE2b-256 e10c4670c18a4342aa6ab73569d4d88a7d1845a1f2b888016f7fd7f5f2eb05ca

See more details on using hashes here.

File details

Details for the file commit_msg_git_hook-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for commit_msg_git_hook-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe266dece2ed87b470f25b50d21b0cb8cea7c62e03b321725abb3ce236eae166
MD5 0b9dacad286c90cccc28dede9e68d45a
BLAKE2b-256 fd37a89ec1b69d3e936e473344eebf103fc35e4fca36fed7ce27f465a70e08fa

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