Skip to content

Instantly share code, notes, and snippets.

@brendanjerwin
Created June 11, 2013 00:18
Show Gist options
  • Save brendanjerwin/5753602 to your computer and use it in GitHub Desktop.
Save brendanjerwin/5753602 to your computer and use it in GitHub Desktop.
#!/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 "[ #{replacement_text}] - " + message }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment