Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Commit-msg hook to prefix with a Chiliproject (Redmine) ID
#!/usr/bin/env ruby
current_branch =`git symbolic-ref HEAD`.chomp.split('/').last
issue_id = current_branch[/\d+/].to_i
commit_message = File.read(ARGV.first).chomp.strip
matches = /^[rmRM\s-]*#\d*(.*)$/.match(commit_message)
commit_message = matches[1].strip if matches
if commit_message == ''
puts "Aborting commit due to empty commit message."
exit 1
end
commit_message = "RM ##{issue_id} #{commit_message}" unless issue_id == 0
File.open(ARGV.first, 'w') {|f| f.puts commit_message }
exit
Owner

pallan commented Nov 2, 2012

There a probably a lot of edge cases that I am missing here, however, it covers the majority of cases my team has to deal with. Therefore I deem it "good enough". :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment