How to do it...

What we want to do in the first example is to check whether or not the defect information is correct. There is no need to release a commit that refers to a defect that does not exist:

  1. We will start by testing the commit-msg hook. First, make a copy of the current hook, then we will force the hook to exit with a non-zero value that will abort the creation of the commit:
$ cp .git/hooks/commit-msg.sample .git/hooks/commit-msg
  1. Now, open the file in your preferred editor and add the following lines to the file:
#!/bin/bash
echo "you are not allowed to commit"
exit 1
  1. Now, we will try to make a commit and see what happens, as follows:
$ echo "Frogs, scallops, and coco shell" >> fishtank.txt
$ git add fishtank.txt
$ git commit ...

Get Git Version Control Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.