mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Prepend hook name to each output line
This commit is contained in:
parent
d525928665
commit
8861b85dae
4 changed files with 15 additions and 2 deletions
|
|
@ -79,6 +79,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
|
||||||
cfgv.Optional('require_serial', cfgv.check_bool, False),
|
cfgv.Optional('require_serial', cfgv.check_bool, False),
|
||||||
cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),
|
cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),
|
||||||
cfgv.Optional('verbose', cfgv.check_bool, False),
|
cfgv.Optional('verbose', cfgv.check_bool, False),
|
||||||
|
cfgv.Optional('prepend_name', cfgv.check_bool, False),
|
||||||
)
|
)
|
||||||
MANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)
|
MANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,9 +218,19 @@ def _run_single_hook(
|
||||||
if files_modified:
|
if files_modified:
|
||||||
_subtle_line('- files were modified by this hook', use_color)
|
_subtle_line('- files were modified by this hook', use_color)
|
||||||
|
|
||||||
if out.strip():
|
hook_output = out.strip()
|
||||||
|
if hook_output:
|
||||||
|
if hook.prepend_name:
|
||||||
|
# Prepends the hook name to each line of its console output
|
||||||
|
hook_output = b'\n'.join(
|
||||||
|
[
|
||||||
|
bytes(f'{hook.name}: ', encoding='utf8') + line
|
||||||
|
for line in hook_output.split(b'\n')
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
output.write_line()
|
output.write_line()
|
||||||
output.write_line_b(out.strip(), logfile_name=hook.log_file)
|
output.write_line_b(hook_output, logfile_name=hook.log_file)
|
||||||
output.write_line()
|
output.write_line()
|
||||||
|
|
||||||
return files_modified or bool(retcode), diff_after
|
return files_modified or bool(retcode), diff_after
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class Hook(NamedTuple):
|
||||||
minimum_pre_commit_version: str
|
minimum_pre_commit_version: str
|
||||||
require_serial: bool
|
require_serial: bool
|
||||||
stages: Sequence[str]
|
stages: Sequence[str]
|
||||||
|
prepend_name: bool
|
||||||
verbose: bool
|
verbose: bool
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -1005,6 +1005,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||||
types_or=[],
|
types_or=[],
|
||||||
verbose=False,
|
verbose=False,
|
||||||
fail_fast=False,
|
fail_fast=False,
|
||||||
|
prepend_name=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue