Wednesday, October 29, 2014

Useful (to me) post-commit hook script for checking commit message

A lot of projects are managed using bug-tracking tool (e.g. JIRA [1], Bugzilla [2], Redmine [3]), and most commits refer to a specified ticket. It's good to enter ticket number in a commit message - it allows other developers find a bug report, read more about a problem, which concern a commit.
I don't know about you, but I often forget about put it in a commit message. So I've prepared simple script, which reminds me about enter ticket message in a message. I'm using this script as a post-commit hook both at work and in my private projects.
I've pushed it to my github repository [4] (I've added also simple instruction - you can find it in a README.md file). Feel free to use and improve it (I'm not a bash and git expert) - patches are welcome ;)

REPO_REGEX parameter

Some of my friends have asked me about REPO_REGEX parameter. So let me clarify; e.g. at work I'm using mostly company's repositories, where should I enter ticket number. But I've got also a few open source repositories, where I don't need to (sometimes even I can't, because it doesn't strongly connected with bug-reporting service) pass this number. To make my life easier, I've added this script as a global. REPO_REGEX allows me define company repositories pattern, so I don't see warning message during committing to a non-company repositories.

Links
[1] https://www.atlassian.com/software/jira
[2] http://www.bugzilla.org/
[3] http://www.redmine.org/
[4] https://github.com/loganek/postcommit-checker