Created
October 7, 2014 04:39
-
-
Save huguesbr/927c75575cf8eb88f283 to your computer and use it in GitHub Desktop.
Git Hook - prepare-commit-msg - auto suffix commit message with issue id
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/ruby | |
# | |
# Called by "git commit" with the | |
# name of the file that has the | |
# commit message, followed by | |
# the description of the commit | |
# message's source. The hook's | |
# purpose is to edit the commit | |
# message file. If the hook fails | |
# with a non-zero status, | |
# the commit is aborted. | |
# | |
# install | |
# cp prepare-commit-msg ./.git/hooks/ | |
# auto suffix every commit with issue id | |
# extract issue id from branch name | |
# git checkout "100-update-ui" | |
# ... | |
# git commit -am "updating ui" | |
# git log --pretty=format:"%s" -1 | |
# > #100 - updating ui | |
message_file = ARGV[0] | |
message = File.read(message_file) | |
branch_name = %x( git symbolic-ref --short HEAD ) | |
if match = /^([^\/]+\/)?(?<issue_id>[0-9]+)-/.match(branch_name) | |
File.open(message_file, 'w') { |f| f.write "##{match[:issue_id]} - #{message}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly what I was looking for. Nice work!