-
-
Save curiouslychase/6225416 to your computer and use it in GitHub Desktop.
Place this in the following path relative to your git repo's root:
.git/hooks/commit-msg
This file contains 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 | |
# 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