feat: Adds just_warn option to allow commit when return value is not zero

This commit is contained in:
Guionardo 2025-08-11 12:12:08 -03:00
parent b74a22d96c
commit 6f0b860928
3 changed files with 10 additions and 3 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@
/.tox
/dist
.vscode/
.venv
build

View file

@ -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'

View file

@ -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, ...]]: