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 /.tox
/dist /dist
.vscode/ .vscode/
.venv
build

View file

@ -292,15 +292,19 @@ def _run_hooks(
) )
retval = 0 retval = 0
prior_diff = _get_diff() prior_diff = _get_diff()
just_warn = False
for hook in hooks: for hook in hooks:
current_retval, prior_diff = _run_single_hook( current_retval, prior_diff = _run_single_hook(
classifier, hook, skips, cols, prior_diff, classifier, hook, skips, cols, prior_diff,
verbose=args.verbose, use_color=args.color, verbose=args.verbose, use_color=args.color,
) )
if not hook.just_warn:
retval |= current_retval retval |= current_retval
if current_retval and (config['fail_fast'] or hook.fail_fast): else:
just_warn |= current_retval
if (current_retval or just_warn) and (config['fail_fast'] or hook.fail_fast):
break 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: if args.all_files:
output.write_line( output.write_line(
'pre-commit hook(s) made changes.\n' 'pre-commit hook(s) made changes.\n'

View file

@ -35,6 +35,7 @@ class Hook(NamedTuple):
require_serial: bool require_serial: bool
stages: Sequence[str] stages: Sequence[str]
verbose: bool verbose: bool
just_warn: bool
@property @property
def install_key(self) -> tuple[Prefix, str, str, tuple[str, ...]]: def install_key(self) -> tuple[Prefix, str, str, tuple[str, ...]]: