mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
Merge pull request #1 from EMSL-MSC/no-commit-branch
No commit branch hook
This commit is contained in:
commit
feb988eb85
3 changed files with 31 additions and 0 deletions
|
|
@ -141,3 +141,9 @@
|
|||
entry: trailing-whitespace-fixer
|
||||
language: python
|
||||
files: \.(asciidoc|adoc|coffee|cpp|css|c|ejs|erb|groovy|h|haml|hh|hpp|hxx|html|in|j2|jade|json|js|less|markdown|md|ml|mli|pp|py|rb|rs|R|scala|scss|sh|slim|tex|tmpl|ts|txt|yaml|yml)$
|
||||
- id: no-commit-to-branch
|
||||
name: Dont commit to branch
|
||||
entry: no-commit-to-branch
|
||||
language: python
|
||||
files: .*
|
||||
always_run: true
|
||||
|
|
|
|||
24
pre_commit_hooks/no_commit_to_branch.py
Normal file
24
pre_commit_hooks/no_commit_to_branch.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import util
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', default='master', help='branch to disallow commits to')
|
||||
parser.add_argument('filenames', nargs='*', help='filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retval = -1
|
||||
branch = util.cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||
chunks = branch.split('/')
|
||||
if chunks[2] == args.b:
|
||||
retval = 0
|
||||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
1
setup.py
1
setup.py
|
|
@ -56,6 +56,7 @@ setup(
|
|||
'pretty-format-json = pre_commit_hooks.pretty_format_json:pretty_format_json',
|
||||
'requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:fix_requirements_txt',
|
||||
'trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:fix_trailing_whitespace',
|
||||
'no-commit-to-branch = pre_commit_hooks.no_commit_to_branch:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue