Add fail_fast support per-hook · pre-commit/pre-commit@63ae399 · GitHub
Skip to content

Commit 63ae399

Browse files
colens3asottile
authored andcommitted
Add fail_fast support per-hook
1 parent ae53a8e commit 63ae399

5 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎pre_commit/clientlib.py‎

Lines changed: 1 addition & 0 deletions

‎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

0 commit comments

Comments
 (0)