Created
November 2, 2012 12:58
-
-
Save pallan/4001241 to your computer and use it in GitHub Desktop.
Commit-msg hook to prefix with a Chiliproject (Redmine) ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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". :-)