From 6f0b860928edcb34964136c4363c79f181a3f6fa Mon Sep 17 00:00:00 2001 From: Guionardo Date: Mon, 11 Aug 2025 12:12:08 -0300 Subject: [PATCH] feat: Adds just_warn option to allow commit when return value is not zero --- .gitignore | 2 ++ pre_commit/commands/run.py | 10 +++++++--- pre_commit/hook.py | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c2021816..a6cf6ddb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /.tox /dist .vscode/ +.venv +build \ No newline at end of file diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 793adbdb..a6251607 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -292,15 +292,19 @@ def _run_hooks( ) retval = 0 prior_diff = _get_diff() + just_warn = False for hook in hooks: current_retval, prior_diff = _run_single_hook( classifier, hook, skips, cols, prior_diff, verbose=args.verbose, use_color=args.color, ) - retval |= current_retval - if current_retval and (config['fail_fast'] or hook.fail_fast): + if not hook.just_warn: + retval |= current_retval + else: + just_warn |= current_retval + if (current_retval or just_warn) and (config['fail_fast'] or hook.fail_fast): break - if retval and args.show_diff_on_failure and prior_diff: + if (retval or just_warn) and args.show_diff_on_failure and prior_diff: if args.all_files: output.write_line( 'pre-commit hook(s) made changes.\n' diff --git a/pre_commit/hook.py b/pre_commit/hook.py index 309cd5be..6794912f 100644 --- a/pre_commit/hook.py +++ b/pre_commit/hook.py @@ -35,6 +35,7 @@ class Hook(NamedTuple): require_serial: bool stages: Sequence[str] verbose: bool + just_warn: bool @property def install_key(self) -> tuple[Prefix, str, str, tuple[str, ...]]: