mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 03:26:53 +00:00
Add a no commit to specific branch hook. (#185)
* add no commit code and config * add the code * remove version tweak * fix logic, remove newline * add Tests and cleanup testing issues * remove extraneous modules * cleanup some pep8 and flake issues * reorder imports * more fixes for syntax checking * code cleanup based off asottile comments * Use Contractions Properly, alphabatize new hook. * Adding support for branches with a slash in them.
This commit is contained in:
parent
b95dcad616
commit
a8592669d9
6 changed files with 87 additions and 0 deletions
25
pre_commit_hooks/no_commit_to_branch.py
Normal file
25
pre_commit_hooks/no_commit_to_branch.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def is_on_branch(protected):
|
||||
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||
chunks = branch.strip().split('/')
|
||||
return '/'.join(chunks[2:]) == protected
|
||||
|
||||
|
||||
def main(argv=[]):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-b', '--branch', default='master', help='branch to disallow commits to')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
return int(is_on_branch(args.branch))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
Loading…
Add table
Add a link
Reference in a new issue