Skip to content

Instantly share code, notes, and snippets.

@thejspr
Created May 14, 2013 14:46
Show Gist options
  • Select an option

  • Save thejspr/5576495 to your computer and use it in GitHub Desktop.

Select an option

Save thejspr/5576495 to your computer and use it in GitHub Desktop.

Revisions

  1. thejspr created this gist May 14, 2013.
    15 changes: 15 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/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) }