Skip to content

Instantly share code, notes, and snippets.

/commit-msg
Created Aug 13, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.