Created
January 17, 2012 01:03
-
-
Save freshtonic/1623926 to your computer and use it in GitHub Desktop.
Git update hook to disallow fast-forwards for master and release branches
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 | |
| $refname = ARGV[0] | |
| $oldrev = ARGV[1] | |
| $newrev = ARGV[2] | |
| $user = ENV['USER'] | |
| puts "Enforcing Policies... \n(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})" | |
| NON_FASTFORWARD_BLACKLIST = [/\brelease\b/, /\bmaster\b/] | |
| # enforces fast-forward only pushes | |
| def check_fast_forward | |
| if NON_FASTFORWARD_BLACKLIST.any?{ |b| $refname =~ b} | |
| missed_refs = `git rev-list #{$newrev}..#{$oldrev}` | |
| missed_ref_count = missed_refs.split("\n").size | |
| if missed_ref_count > 0 | |
| puts "[POLICY] Cannot push a non fast-forward reference" | |
| exit 1 | |
| end | |
| end | |
| end | |
| check_fast_forward |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should live in .git/hooks and be named 'update'