Created
November 26, 2013 16:06
-
-
Save westhood/7661024 to your computer and use it in GitHub Desktop.
git hook script in update phrase to ensure only specific users can commit to given 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 python | |
| import sys | |
| import re | |
| import pwd | |
| import os | |
| ptn = re.compile("refs/heads/(.*)") | |
| allows_only = { | |
| "master": ["yuanye4"] | |
| } | |
| def check(): | |
| uname = pwd.getpwuid(os.getuid())[0] | |
| refname, old, new = sys.argv[1:] | |
| m = ptn.match(refname) | |
| if m: | |
| branch = m.groups()[0] | |
| if branch in allows_only: | |
| users = allows_only[branch] | |
| if uname not in users: | |
| print ":(, sorry %s!" % uname | |
| print "branch *%s* allows only users below to update:" % branch | |
| print ", ".join(users) | |
| return 1 | |
| return 0 | |
| sys.exit(check()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment