From 6c464e27020b40e0fbcf9ce0ad217b927b1f79eb Mon Sep 17 00:00:00 2001 From: "Evan J. Felix" Date: Thu, 19 Jan 2017 14:56:55 -0800 Subject: [PATCH 1/3] add no commit code and config --- hooks.yaml | 6 ++++++ setup.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hooks.yaml b/hooks.yaml index 11a414c..9f51926 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -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 diff --git a/setup.py b/setup.py index f92f821..1f9fb80 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='pre_commit_hooks', description='Some out-of-the-box hooks for pre-commit.', url='https://github.com/pre-commit/pre-commit-hooks', - version='0.6.0', + version='0.6.0a', author='Anthony Sottile', author_email='asottile@umich.edu', @@ -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', ], }, ) From 3d0466f30beab32bd204f3e3ff87d7e78697a2b6 Mon Sep 17 00:00:00 2001 From: "Evan J. Felix" Date: Thu, 19 Jan 2017 15:07:09 -0800 Subject: [PATCH 2/3] add the code --- pre_commit_hooks/no_commit_to_branch.py | 24 ++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 pre_commit_hooks/no_commit_to_branch.py diff --git a/pre_commit_hooks/no_commit_to_branch.py b/pre_commit_hooks/no_commit_to_branch.py new file mode 100644 index 0000000..01dee5a --- /dev/null +++ b/pre_commit_hooks/no_commit_to_branch.py @@ -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()) diff --git a/setup.py b/setup.py index 1f9fb80..2265df7 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='pre_commit_hooks', description='Some out-of-the-box hooks for pre-commit.', url='https://github.com/pre-commit/pre-commit-hooks', - version='0.6.0a', + version='0.6.0b', author='Anthony Sottile', author_email='asottile@umich.edu', From 232394b589660c6a2bc0c7387fbe453ee395d7d3 Mon Sep 17 00:00:00 2001 From: "Evan J. Felix" Date: Thu, 19 Jan 2017 15:09:23 -0800 Subject: [PATCH 3/3] remove version tweak --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2265df7..9c2c2d0 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='pre_commit_hooks', description='Some out-of-the-box hooks for pre-commit.', url='https://github.com/pre-commit/pre-commit-hooks', - version='0.6.0b', + version='0.6.0', author='Anthony Sottile', author_email='asottile@umich.edu',