Skip to content

Instantly share code, notes, and snippets.

@jens
Created September 15, 2011 13:46
Show Gist options
  • Save jens/1219260 to your computer and use it in GitHub Desktop.
Save jens/1219260 to your computer and use it in GitHub Desktop.
Get story id from branch name and add pivotal reference to commit message
#!/usr/bin/env ruby
#
# Copy this file into .git/hooks and chmod +x
#
branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].to_s
PIVOTAL_REFERENCE = /s-(\d+)/i
if story_match = branchname.match(PIVOTAL_REFERENCE)
story_id = story_match.captures.first
reference = "[#%s]" % story_id
`echo "#{reference}"|cat - #{ARGV[0]} > /tmp/out && mv /tmp/out #{ARGV[0]}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment