Created
August 24, 2010 02:28
-
-
Save jmeridth/546798 to your computer and use it in GitHub Desktop.
update githook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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