Enforce adding issue numbers to git commit messages

Run this in Git bash/console/command prompt/Powershell with Git installed/in the path


git/hooks/commit-msg

Then replace the contents of the text file with this

#!/usr/bin/env ruby

message_file = ARGV[0]
message = File.read(message_file)
# $regex = /\[ref: (\d+)\]/
$regex = /[addresses|fixes]\ \#\d+/
if !$regex.match(message)

puts "[POLICY] Your message is not formatted correctly"

exit 1

end

The most interesting thing about this is the regex that looks for a commit message that has a string with either “addresses” or “fixes” followed by a number. I use this with Bitbucket’s issue tracking service to automatically associate commits with issues.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s