Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Created April 19, 2013 17:55
Show Gist options
  • Save jacaetevha/5422000 to your computer and use it in GitHub Desktop.
Save jacaetevha/5422000 to your computer and use it in GitHub Desktop.
[__TICKET_NUMBER__]
git config commit.template path/to/.gitmessage.txt
#!/usr/bin/env 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.
#
message_file = ARGV[0]
message = File.read(message_file)
pivotal_task_number = `git rev-parse --abbrev-ref HEAD | grep --only-matching '[0-9]*$'`.strip
replacement_text = pivotal_task_number.length == 0 ? 'NOTICKET' : "##{pivotal_task_number}"
File.open(message_file, 'w') { |f| f.write message.sub('__TICKET_NUMBER__', replacement_text) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment