Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix per-hook fail_fast to not fail on previous failures #3168

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pre_commit/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/commands/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
Expand Down