Setup pre-commit hook and check commit message

pre-commit to check coding convention:

Create a file to use as pre-commit hook, in this example, we setup the hook to run gradle checkStyle command.

mkdir git-hooks
touch git-hooks/pre-commit.sh

commit-msg.sh to check commit message standard

Create a file to use as commit-msg hook, in this example, we setup the hook to run check the commit message if it contains USxxxxx prefix using regex.

touch git-hooks/commit-msg.sh

Setup script to apply configuration to git repo

touch setup-pre-commit-hook.sh

Run setup command to apply hooks

sh ./setup-pre-commit-hook.sh

Check the config

After setting up all the hooks needed, we can perform a simple check by changing the code and try to commit

git commit -a -m “Invalid commit message”
Error message indicating commit message is invalid

Tadaaa!!!!!!!!!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store