Created
July 21, 2014 10:51
-
-
Save pjmartorell/6456a5ffa7f7ff9d3195 to your computer and use it in GitHub Desktop.
Prepend automatically a reference to the issue number to commit tasks
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 | |
# Git commit-msg hook. Prepend a reference to the issue number of the branch name to commit tasks. | |
# If your branch name is in the numeric form "issue_12345", also prepend "refs #12345" to commit messages, | |
# unless "refs #12345" is manually provided inline. | |
# | |
# Place code into .git/hooks/prepare-commit-msg and give it executable permissions | |
# cd .git/hooks | |
# wget https://gist.github.com/pjmartorell/6456a5ffa7f7ff9d3195 | |
# chmod 755 prepare-commit-msg | |
branch = `git branch`.scan(/\* (.*)/).flatten[0] | |
exit 0 if branch == "master" | |
issue_no = branch.gsub(/[^\d]/, '') | |
exit 0 if issue_no.nil? | |
message_file = ARGV[0] | |
message = File.read(message_file).strip | |
message = "refs ##{issue_no} " + message unless message.match("refs #") | |
File.open(message_file, 'w') {|f| f.write message } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment