Skip to content

Instantly share code, notes, and snippets.

@teddyzetterlund
Created June 25, 2012 21:43
Show Gist options
  • Save teddyzetterlund/2991476 to your computer and use it in GitHub Desktop.
Save teddyzetterlund/2991476 to your computer and use it in GitHub Desktop.
Rename to pre_commit and put it in <your-project>/.git/hooks to require commits to follow policy
#!/usr/bin/env ruby
# Compare commit message formatting to formatting policy.
#
# Message should include a Pivotal Story ID reference
# and an optional state change keyword.
#
# Example: [Fixes #12345]
message_file = ARGV[0]
message = File.read(message_file)
$actions = %w(fix fixes complete completes finish finishes)
$regex = /\[(#{$actions.join("|")})?\s?#(\d+)\]/i
if !$regex.match(message)
puts "[POLICY] Your message does not include a story ID"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment