Run this in Git bash/console/command prompt/Powershell with Git installed/in the path
Then replace the contents of the text file with this
#!/usr/bin/env ruby message_file = ARGV 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.