-
-
Save karavanis/9467657 to your computer and use it in GitHub Desktop.
This file contains hidden or 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. If your branch name is in the form "SYSRAP-123", automatically | |
# adds "Refs #SYSRAP-123." to commit messages unless they mention "#SYSRAP-123" already. | |
# | |
# By Henrik Nyh <http://henrik.nyh.se> 2009-09-10 under the MIT License. | |
# | |
# | |
# Install: | |
# | |
# cd your_project | |
# curl https://gist.githubusercontent.com/sbosx/9467657/raw/062b7866e26a7adb6738414afae4f8bd89c9c978/commit-msg -o .git/hooks/commit-msg && chmod u+x .git/hooks/commit-msg | |
branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1] | |
ticket_number = branchname.to_s.match(/SYSRAP-(\d+)/) && $1 | |
exit unless ticket_number | |
message_file = ARGV[0] | |
message = File.read(message_file) | |
exit if message.include?("#SYSRAP-#{ticket_number}") | |
message.strip! | |
message.sub!(/([^[:punct:]])\z/, "\\1.") # Add trailing period if missing. | |
message = ["#SYSRAP-#{ticket_number}", message].join(" ") | |
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