Skip to content

Instantly share code, notes, and snippets.

@marcelmorgan
Created October 11, 2016 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelmorgan/5a3135cd4aa16fc5d666356631472d78 to your computer and use it in GitHub Desktop.
Save marcelmorgan/5a3135cd4aa16fc5d666356631472d78 to your computer and use it in GitHub Desktop.
#!/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