Using external information in the commit message
The commit hook is executed when you close the commit message editor. It can, among other things, be used to manipulate the commit message or review the commit message by machine to check whether it has a specific format.
In this recipe, we will be manipulating and checking the content of a commit message.
Getting ready
To start this exercise, we just need to create a branch and check it out. We need to disable the current prepare-commit-msg hook; we can do this by simply renaming it. Now, we can start working on the commit-msg hook by using the following command:
git checkout -b commit-msg-example Switched to a new branch 'commit-msg-example' $ mv .git/hooks/prepare-commit-msg .git/hooks/prepare-commit-msg.example
How to do it...
What we want to do in the first example is to check whether the defect information is correct. There is no need to release a commit that refers to a defect that does not exist:
We will start by testing the commit-msg...