Skip to content

Instantly share code, notes, and snippets.

@thejspr
Created May 14, 2013 14:46
Show Gist options
  • Save thejspr/5576495 to your computer and use it in GitHub Desktop.
Save thejspr/5576495 to your computer and use it in GitHub Desktop.
Add pivotal tracker story number to git commit messages.
#!/usr/bin/env ruby
# put this in .git/hooks/prepare-commit-msg
message_file = ARGV[0]
message = File.read(message_file)
pivotal_story_number = `git rev-parse --abbrev-ref HEAD | grep --only-matching '[0-9]*$'`.strip
# do not add anything if the branch doesn't have a story number or the message already contains one.
unless pivotal_story_number.empty? || message =~ /^\[#\d+\]/
message = "[##{pivotal_story_number}]\n#{message}"
end
File.open(message_file, 'w') { |f| f.write(message) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment