mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Hide passed lines in --quiet mode
Downside is delay output on failed hooks
This commit is contained in:
parent
db412bc67d
commit
5c1a7499cf
1 changed files with 27 additions and 9 deletions
|
|
@ -123,6 +123,7 @@ def _get_skips(environ: EnvironT) -> Set[str]:
|
||||||
|
|
||||||
SKIPPED = 'Skipped'
|
SKIPPED = 'Skipped'
|
||||||
NO_FILES = '(no files to check)'
|
NO_FILES = '(no files to check)'
|
||||||
|
FAILED = 'Failed'
|
||||||
|
|
||||||
|
|
||||||
def _subtle_line(s: str, use_color: bool) -> None:
|
def _subtle_line(s: str, use_color: bool) -> None:
|
||||||
|
|
@ -176,7 +177,8 @@ def _run_single_hook(
|
||||||
out = b''
|
out = b''
|
||||||
else:
|
else:
|
||||||
# print hook and dots first in case the hook takes a while to run
|
# print hook and dots first in case the hook takes a while to run
|
||||||
output.write(_start_msg(start=hook.name, end_len=6, cols=cols))
|
if not quiet:
|
||||||
|
output.write(_start_msg(start=hook.name, end_len=6, cols=cols))
|
||||||
|
|
||||||
if not hook.pass_filenames:
|
if not hook.pass_filenames:
|
||||||
filenames = ()
|
filenames = ()
|
||||||
|
|
@ -189,16 +191,32 @@ def _run_single_hook(
|
||||||
# if the hook makes changes, fail the commit
|
# if the hook makes changes, fail the commit
|
||||||
files_modified = diff_before != diff_after
|
files_modified = diff_before != diff_after
|
||||||
|
|
||||||
if retcode or files_modified:
|
if not quiet:
|
||||||
print_color = color.RED
|
# Finish the partial line of output...
|
||||||
status = 'Failed'
|
if retcode or files_modified:
|
||||||
else:
|
print_color = color.RED
|
||||||
print_color = color.GREEN
|
status = FAILED
|
||||||
status = 'Passed'
|
else:
|
||||||
|
print_color = color.GREEN
|
||||||
output.write_line(color.format_color(status, print_color, use_color))
|
status = 'Passed'
|
||||||
|
output.write_line(
|
||||||
|
color.format_color(status, print_color, use_color),
|
||||||
|
)
|
||||||
|
|
||||||
if verbose or hook.verbose or retcode or files_modified:
|
if verbose or hook.verbose or retcode or files_modified:
|
||||||
|
if quiet:
|
||||||
|
# Normal would have written this in two stages:
|
||||||
|
output.write(
|
||||||
|
_full_msg(
|
||||||
|
start=hook.name,
|
||||||
|
postfix=NO_FILES,
|
||||||
|
end_msg=FAILED,
|
||||||
|
end_color=color.RED,
|
||||||
|
use_color=use_color,
|
||||||
|
cols=cols,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
_subtle_line(f'- hook id: {hook.id}', use_color)
|
_subtle_line(f'- hook id: {hook.id}', use_color)
|
||||||
|
|
||||||
if (verbose or hook.verbose) and duration is not None:
|
if (verbose or hook.verbose) and duration is not None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue