Skip to content

Instantly share code, notes, and snippets.

@pallan
Created November 2, 2012 12:58
Show Gist options
  • Save pallan/4001241 to your computer and use it in GitHub Desktop.
Save pallan/4001241 to your computer and use it in GitHub Desktop.
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
@pallan
Copy link
Author

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