Fix no-commit-to-branch when not on a branch

This commit is contained in:
Anthony Sottile
2018-02-19 12:56:14 -08:00
parent 2f1e5e2abf
commit 93f319c1f8
2 changed files with 20 additions and 13 deletions

View File

@ -1,21 +1,25 @@
from __future__ import print_function
import argparse
import sys
from pre_commit_hooks.util import CalledProcessError
from pre_commit_hooks.util import cmd_output
def is_on_branch(protected):
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
try:
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
except CalledProcessError:
return False
chunks = branch.strip().split('/')
return '/'.join(chunks[2:]) == protected
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', default='master',
help='branch to disallow commits to',
)
args = parser.parse_args(argv)
@ -23,4 +27,4 @@ def main(argv=[]):
if __name__ == '__main__':
sys.exit(main(sys.argv))
exit(main())