Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2b74e3

Browse files
authored
Merge pull request #803 from mblayman/args-hook-only
Run only the specified hook even when stages exist in config.
2 parents f2da2c4 + fd1bc21 commit f2b74e3

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

pre_commit/commands/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def run(runner, store, args, environ=os.environ):
256256
for _, hook in repo.hooks:
257257
if (
258258
(not args.hook or hook['id'] == args.hook) and
259-
not hook['stages'] or args.hook_stage in hook['stages']
259+
(not hook['stages'] or args.hook_stage in hook['stages'])
260260
):
261261
repo_hooks.append((repo, hook))
262262

tests/commands/run_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,34 @@ def test_include_exclude_does_search_instead_of_match(some_filenames):
762762
def test_include_exclude_exclude_removes_files(some_filenames):
763763
ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
764764
assert ret == ['.pre-commit-hooks.yaml']
765+
766+
767+
def test_args_hook_only(cap_out, store, repo_with_passing_hook):
768+
config = OrderedDict((
769+
('repo', 'local'),
770+
(
771+
'hooks', (
772+
OrderedDict((
773+
('id', 'flake8'),
774+
('name', 'flake8'),
775+
('entry', "'{}' -m flake8".format(sys.executable)),
776+
('language', 'system'),
777+
('stages', ['commit']),
778+
)), OrderedDict((
779+
('id', 'do_not_commit'),
780+
('name', 'Block if "DO NOT COMMIT" is found'),
781+
('entry', 'DO NOT COMMIT'),
782+
('language', 'pygrep'),
783+
)),
784+
),
785+
),
786+
))
787+
add_config_to_repo(repo_with_passing_hook, config)
788+
stage_a_file()
789+
ret, printed = _do_run(
790+
cap_out,
791+
store,
792+
repo_with_passing_hook,
793+
run_opts(hook='do_not_commit'),
794+
)
795+
assert b'flake8' not in printed

0 commit comments

Comments
 (0)