Created
October 11, 2016 20:07
-
-
Save marcelmorgan/5a3135cd4aa16fc5d666356631472d78 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 | |
# place in .git/hooks/prepare-commit-msg | |
branch_name = `git rev-parse --abbrev-ref HEAD` | |
commit_file = ARGV.first | |
first_line = File.open(commit_file, &:readline) | |
if first_line.strip.empty? && (match = branch_name.match(/(^.*\d+)/i)) | |
# Assumes a ticket number ends in a number for e.g. #1, PROJECT_NAME-3 | |
commit_prefix = match.captures.first.upcase | |
previous_commit_msg = File.read(commit_file) | |
File.open(commit_file, 'w') do |f| | |
f.puts commit_prefix | |
f.puts previous_commit_msg | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment