Skip to content

Commit

Permalink
Add fail_fast support per-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
colens3 authored and asottile committed Oct 22, 2021
1 parent ae53a8e commit 63ae399
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions pre_commit/clientlib.py
Expand Up @@ -70,6 +70,7 @@ def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
),
cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),
cfgv.Optional('always_run', cfgv.check_bool, False),
cfgv.Optional('fail_fast', cfgv.check_bool, False),
cfgv.Optional('pass_filenames', cfgv.check_bool, True),
cfgv.Optional('description', cfgv.check_string, ''),
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
Expand Down
2 changes: 1 addition & 1 deletion pre_commit/commands/run.py
Expand Up @@ -290,7 +290,7 @@ def _run_hooks(
verbose=args.verbose, use_color=args.color,
)
retval |= current_retval
if retval and config['fail_fast']:
if retval and (config['fail_fast'] or hook.fail_fast):
break
if retval and args.show_diff_on_failure and prior_diff:
if args.all_files:
Expand Down
1 change: 1 addition & 0 deletions pre_commit/hook.py
Expand Up @@ -27,6 +27,7 @@ class Hook(NamedTuple):
additional_dependencies: Sequence[str]
args: Sequence[str]
always_run: bool
fail_fast: bool
pass_filenames: bool
description: str
language_version: str
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/run_test.py
Expand Up @@ -985,6 +985,18 @@ def test_fail_fast(cap_out, store, repo_with_failing_hook):
assert printed.count(b'Failing hook') == 1


def test_fail_fast_per_hook(cap_out, store, repo_with_failing_hook):
with modify_config() as config:
# More than one hook
config['repos'][0]['hooks'] *= 2
config['repos'][0]['hooks'][0]['fail_fast'] = True
stage_a_file()

ret, printed = _do_run(cap_out, store, repo_with_failing_hook, run_opts())
# it should have only run one hook
assert printed.count(b'Failing hook') == 1


def test_classifier_removes_dne():
classifier = Classifier(('this_file_does_not_exist',))
assert classifier.filenames == []
Expand Down
1 change: 1 addition & 0 deletions tests/repository_test.py
Expand Up @@ -1002,6 +1002,7 @@ def test_manifest_hooks(tempdir_factory, store):
types=['file'],
types_or=[],
verbose=False,
fail_fast=False,
)


Expand Down

0 comments on commit 63ae399

Please sign in to comment.