Skip to content

Commit b319d6f

Browse files
committed
Add a hook option that allows stdout to be printed when exit code is 0 (pre-commit#695)
1 parent 7f0b427 commit b319d6f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def _make_argparser(filenames_help):
6868
schema.Optional('log_file', schema.check_string, ''),
6969
schema.Optional('minimum_pre_commit_version', schema.check_string, '0'),
7070
schema.Optional('stages', schema.check_array(schema.check_string), []),
71+
schema.Optional('verbose', schema.check_bool, False),
7172
)
7273
MANIFEST_SCHEMA = schema.Array(MANIFEST_HOOK_DICT)
7374

pre_commit/commands/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
130130

131131
output.write_line(color.format_color(pass_fail, print_color, args.color))
132132

133-
if (stdout or stderr or file_modifications) and (retcode or args.verbose):
133+
if (
134+
(stdout or stderr or file_modifications) and
135+
(retcode or args.verbose or hook['verbose'])
136+
):
134137
output.write_line('hookid: {}\n'.format(hook['id']))
135138

136139
# Print a message if failing due to file modifications

tests/commands/run_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ def test_always_run_alt_config(
292292
)
293293

294294

295+
def test_hook_verbose_enabled(
296+
cap_out, repo_with_passing_hook, mock_out_store_directory,
297+
):
298+
with modify_config() as config:
299+
config['repos'][0]['hooks'][0]['always_run'] = True
300+
config['repos'][0]['hooks'][0]['verbose'] = True
301+
302+
_test_run(
303+
cap_out,
304+
repo_with_passing_hook,
305+
{},
306+
(b'Hello World',),
307+
0,
308+
stage=False,
309+
)
310+
311+
295312
@pytest.mark.parametrize(
296313
('origin', 'source', 'expect_failure'),
297314
(

tests/repository_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,4 +789,5 @@ def test_manifest_hooks(tempdir_factory, store):
789789
'stages': [],
790790
'types': ['file'],
791791
'exclude_types': [],
792+
'verbose': False,
792793
}

0 commit comments

Comments
 (0)