mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2025-08-14 09:27:21 +08:00
Fix no-commit-to-branch when not on a branch
This commit is contained in:
@ -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())
|
||||
|
Reference in New Issue
Block a user