mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add fail_fast support per-hook
This commit is contained in:
parent
ae53a8eb65
commit
63ae399db0
5 changed files with 16 additions and 1 deletions
|
|
@ -70,6 +70,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
|
||||||
),
|
),
|
||||||
cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),
|
cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),
|
||||||
cfgv.Optional('always_run', cfgv.check_bool, False),
|
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('pass_filenames', cfgv.check_bool, True),
|
||||||
cfgv.Optional('description', cfgv.check_string, ''),
|
cfgv.Optional('description', cfgv.check_string, ''),
|
||||||
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
|
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ def _run_hooks(
|
||||||
verbose=args.verbose, use_color=args.color,
|
verbose=args.verbose, use_color=args.color,
|
||||||
)
|
)
|
||||||
retval |= current_retval
|
retval |= current_retval
|
||||||
if retval and config['fail_fast']:
|
if retval and (config['fail_fast'] or hook.fail_fast):
|
||||||
break
|
break
|
||||||
if retval and args.show_diff_on_failure and prior_diff:
|
if retval and args.show_diff_on_failure and prior_diff:
|
||||||
if args.all_files:
|
if args.all_files:
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class Hook(NamedTuple):
|
||||||
additional_dependencies: Sequence[str]
|
additional_dependencies: Sequence[str]
|
||||||
args: Sequence[str]
|
args: Sequence[str]
|
||||||
always_run: bool
|
always_run: bool
|
||||||
|
fail_fast: bool
|
||||||
pass_filenames: bool
|
pass_filenames: bool
|
||||||
description: str
|
description: str
|
||||||
language_version: str
|
language_version: str
|
||||||
|
|
|
||||||
|
|
@ -985,6 +985,18 @@ def test_fail_fast(cap_out, store, repo_with_failing_hook):
|
||||||
assert printed.count(b'Failing hook') == 1
|
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():
|
def test_classifier_removes_dne():
|
||||||
classifier = Classifier(('this_file_does_not_exist',))
|
classifier = Classifier(('this_file_does_not_exist',))
|
||||||
assert classifier.filenames == []
|
assert classifier.filenames == []
|
||||||
|
|
|
||||||
|
|
@ -1002,6 +1002,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||||
types=['file'],
|
types=['file'],
|
||||||
types_or=[],
|
types_or=[],
|
||||||
verbose=False,
|
verbose=False,
|
||||||
|
fail_fast=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue