Merge pull request #3168 from pre-commit/fix-fail-fast

fix per-hook fail_fast to not fail on previous failures
This commit is contained in:
Anthony Sottile 2024-03-24 13:28:36 -04:00 committed by GitHub
commit d46c8fc051
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -298,7 +298,7 @@ def _run_hooks(
verbose=args.verbose, use_color=args.color,
)
retval |= current_retval
if retval and (config['fail_fast'] or hook.fail_fast):
if current_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:

View file

@ -1088,6 +1088,22 @@ def test_fail_fast_per_hook(cap_out, store, repo_with_failing_hook):
assert printed.count(b'Failing hook') == 1
def test_fail_fast_not_prev_failures(cap_out, store, repo_with_failing_hook):
with modify_config() as config:
config['repos'].append({
'repo': 'meta',
'hooks': [
{'id': 'identity', 'fail_fast': True},
{'id': 'identity', 'name': 'run me!'},
],
})
stage_a_file()
ret, printed = _do_run(cap_out, store, repo_with_failing_hook, run_opts())
# should still run the last hook since the `fail_fast` one didn't fail
assert printed.count(b'run me!') == 1
def test_classifier_removes_dne():
classifier = Classifier(('this_file_does_not_exist',))
assert classifier.filenames == []