configureable git commit hook
Downlod the binary, put it into a folder of your $PATH (for example. /usr/local/bin).
Ensure your user has execution permissions on that file.
There are several places you can put the configuration.
Create a config file named git-commit-hook.yaml
.
Create the configuration below your user folder:
/home/user/.config/git-commit-hook
"project xyz":
# path to the git repository
path: "/home/nils/projects/xyz/.git"
# define types of branch and a pattern to identify the type for the current branch you are working on
branch:
master: "^(origin\\/)*master"
# define a commit message template per branch type, or as here for all (*) branch types
template:
"*": "{.BranchName}: {.CommitMessage}"
# define validation rules per branch type
validation:
master:
"^.*(#\\d*)+.*$" : must have a ticket reference (eg. #267)
Watch out the test fixture for full feature sample
Use the subcommand install
to activate the commit-message-hook in your repository.
There are some useful subcommands which ease the use of the commit-message hook.
Installs the commit-hook in the configured repositories.
You need to specify either -p or -a.
- -p to install in the given repository (eg. -p "project xyz")
- -a to install in all configured repositories
If there's already a commit-message-hook installed, you can overwrite by adding -f
.
Uninstalls the commit-hook from the configured repositories.
You need to specify either -p or -a.
- -p to uninstall from the given repository (eg. -p "project xyz")
- -a to uninstall from all configured repositories
Gives an overview of the configuration and the installed commit hooks
The test command is useful to test configuration and simulate a commit-situation.
You may input the following parameters:
- -p project name
- -b branch name
- m commit message
Sample:
git-commit-hook test -m "short commit message" -b master -p testrepo
in this case, validation will fail, since it's required to give a ticket/issue reference in the commit message.
testing configuration '/home/nils/.config/git-commit-hook/git-commit-hook.yaml':
project : testrepo
branch : master
commit message : short commit message
validation error for branch 'master'
at least expected one of the following to match
- must have a ticket reference (eg. #267)
If you pass a valid commit message
git-commit-hook test -m "fix #121" -b master -p testrepo
shows not validation errors, but shows the finally rendered message.
testing configuration '/home/nils/.config/git-commit-hook/git-commit-hook.yaml':
project : testrepo
branch : master
commit message : fix #121
would generate the following commit message:
fix #121