Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created August 24, 2010 02:28
Show Gist options
  • Select an option

  • Save jmeridth/546798 to your computer and use it in GitHub Desktop.

Select an option

Save jmeridth/546798 to your computer and use it in GitHub Desktop.
update githook
#!/usr/bin/env ruby
# Git update hook
# Policy enforcement
# Do not validate merge commits
# Commit message must be in format:
#
# 'T1234
# awesome commit message'
#
$refname = ARGV[0]
$oldrev = ARGV[1]
$newrev = ARGV[2]
$user = ENV['USER']
puts "Enforcing Policies... \n(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
# enforced custom commit message format
def check_message_format
return if $refname =~ /^refs\/tags\/.*$/
regex = /^\n*(T|t)(\d+)\n{1,}.+$/
missed_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n")
missed_revs.each do |rev|
message = `git cat-file commit #{rev} | sed '1,/^$/d'`
next if message =~ /Merge branch|Reverted/
if message !~ regex
puts "[POLICY] Your message is not formatted correctly"
exit 1
end
end
end
check_message_format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment