pre_commit: expose fail-fast argument for run subcommand

This patch exposes the fail-fast feature as a command-line argument for the run
subcommand, allowing to run pre-commit to stop at the first failed hook without
the need of temporarily writing it to the configuration file when temporarily
needed.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
This commit is contained in:
Luís Ferreira 2021-10-03 00:34:39 +01:00
parent d021bbfabd
commit 61efc539a4
No known key found for this signature in database
GPG key ID: 730750D54B7A9F66
5 changed files with 23 additions and 2 deletions

View file

@ -973,7 +973,7 @@ def test_pass_filenames(
assert (b'foo.py' in printed) == pass_filenames
def test_fail_fast(cap_out, store, repo_with_failing_hook):
def test_fail_fast_config(cap_out, store, repo_with_failing_hook):
with modify_config() as config:
# More than one hook
config['fail_fast'] = True
@ -985,6 +985,19 @@ def test_fail_fast(cap_out, store, repo_with_failing_hook):
assert printed.count(b'Failing hook') == 1
def test_fail_fast_args(cap_out, store, repo_with_failing_hook):
with modify_config() as config:
# More than one hook
config['repos'][0]['hooks'] *= 2
stage_a_file()
ret, printed = _do_run(
cap_out, store, repo_with_failing_hook, run_opts(fail_fast=True),
)
# 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 == []