Skip to content

Instantly share code, notes, and snippets.

Created August 13, 2013 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6225414 to your computer and use it in GitHub Desktop.
Save anonymous/6225414 to your computer and use it in GitHub Desktop.
JIRA commit hook for github commits.
#!/usr/bin/env ruby
# Hook into the message and append the branch name so that we don't have to
# manually do it ourselves!
# This is the message that you put when you do:
# `git commit -m "This is my message"
message_file = ARGV[0]
message = File.read(message_file).strip
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
# We don't want to do this if we're on master, that'd be weird!
if branch_name != "master"
# Checks if the branch name is already in the commit message
unless message.include?branch_name
prepend = "[#{branch_name}] "
message = "#{prepend} #{message}"
end
puts message
# Rewrite the commit message with the branch name in front.
File.open(message_file, "w") { |f|
f.write message
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment