You can extend the functionality of the prepare-commit-msg hook easily, but you should bear in mind that the waiting time for fetching some information should be worth the benefits. One thing that is usually easy to check is a dirty work area.
Here, we need to use the git status command in the prepare commit message hook, and we need to predict whether we will have modified files after the commit:
- To check this, we need to have something staged for committing and some unstaged changes, as follows:
$ git status On branch master nothing to commit, working directory clean
- Now, modify the fishtank.txt file:
$ echo "saltwater" >> fishtank.txt
- Use git status --porcelain to check the work area:
$ git status --porcelain M fishtank.txt ...