Skip to content

Commit 663a766

Browse files
authored
Merge pull request pre-commit#2097 from colens3/master
Support fail_fast on check level
2 parents ae53a8e + 63ae399 commit 663a766

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
7070
),
7171
cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),
7272
cfgv.Optional('always_run', cfgv.check_bool, False),
73+
cfgv.Optional('fail_fast', cfgv.check_bool, False),
7374
cfgv.Optional('pass_filenames', cfgv.check_bool, True),
7475
cfgv.Optional('description', cfgv.check_string, ''),
7576
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),

pre_commit/commands/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def _run_hooks(
290290
verbose=args.verbose, use_color=args.color,
291291
)
292292
retval |= current_retval
293-
if retval and config['fail_fast']:
293+
if retval and (config['fail_fast'] or hook.fail_fast):
294294
break
295295
if retval and args.show_diff_on_failure and prior_diff:
296296
if args.all_files:

pre_commit/hook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Hook(NamedTuple):
2727
additional_dependencies: Sequence[str]
2828
args: Sequence[str]
2929
always_run: bool
30+
fail_fast: bool
3031
pass_filenames: bool
3132
description: str
3233
language_version: str

tests/commands/run_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,18 @@ def test_fail_fast(cap_out, store, repo_with_failing_hook):
985985
assert printed.count(b'Failing hook') == 1
986986

987987

988+
def test_fail_fast_per_hook(cap_out, store, repo_with_failing_hook):
989+
with modify_config() as config:
990+
# More than one hook
991+
config['repos'][0]['hooks'] *= 2
992+
config['repos'][0]['hooks'][0]['fail_fast'] = True
993+
stage_a_file()
994+
995+
ret, printed = _do_run(cap_out, store, repo_with_failing_hook, run_opts())
996+
# it should have only run one hook
997+
assert printed.count(b'Failing hook') == 1
998+
999+
9881000
def test_classifier_removes_dne():
9891001
classifier = Classifier(('this_file_does_not_exist',))
9901002
assert classifier.filenames == []

tests/repository_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ def test_manifest_hooks(tempdir_factory, store):
10021002
types=['file'],
10031003
types_or=[],
10041004
verbose=False,
1005+
fail_fast=False,
10051006
)
10061007

10071008

0 commit comments

Comments
 (0)