mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
define more branch protected
This commit is contained in:
parent
5bf6c09bfa
commit
0e20aa09e2
2 changed files with 16 additions and 10 deletions
|
|
@ -6,20 +6,26 @@ import sys
|
|||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def is_on_branch(protected):
|
||||
def is_on_branch(protected=()):
|
||||
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||
chunks = branch.strip().split('/')
|
||||
return '/'.join(chunks[2:]) == protected
|
||||
position = '/'.join(chunks[2:])
|
||||
return position in (protected or ('master',))
|
||||
|
||||
|
||||
def main(argv=[]):
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-b', '--branch', default='master', help='branch to disallow commits to')
|
||||
'-b',
|
||||
'--branch',
|
||||
action='append',
|
||||
dest='branches',
|
||||
help='branch to disallow commits to'
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
return int(is_on_branch(args.branch))
|
||||
return int(is_on_branch(args.branches))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue