mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
When run is called with -v, then show hook.description if available.
When developers run the pre-commit, they don't always understand what to or where to find more information. The hook description field is already present and often used to provide more descriptive information. For brevity this is not shown in normal cases, but this PR changes the tool behavior to show the description in verbose mode (`-v`). So most users won't see any difference but this can easily be enabled for people who want it. Alternatives considered: * Always show the description: Some people may not like this though as it can be spammy. * Provide a new field: Possible but seems to be just more work with description already present and not otherwise used. * Show the `repo` link. This is at the wrong level and has a slightly different purpose. Though description can just be set to the same url where that is correct.
This commit is contained in:
parent
85fe18253f
commit
689f1203f7
4 changed files with 32 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,6 +1,8 @@
|
|||
*.egg-info
|
||||
*.py[co]
|
||||
*.pytest_cache
|
||||
/.coverage
|
||||
/.tox
|
||||
/build
|
||||
/dist
|
||||
.vscode/
|
||||
|
|
|
|||
|
|
@ -222,6 +222,13 @@ def _run_single_hook(
|
|||
|
||||
if retcode:
|
||||
_subtle_line(f'- exit code: {retcode}', use_color)
|
||||
if verbose and hook.description:
|
||||
if '\n' in hook.description:
|
||||
_subtle_line('- description: |', use_color)
|
||||
for l in hook.description.splitlines():
|
||||
_subtle_line(' ' + l, use_color)
|
||||
else:
|
||||
_subtle_line(f'- description: {hook.description}', use_color)
|
||||
|
||||
# Print a message if failing due to file modifications
|
||||
if files_modified:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
- id: failing_hook
|
||||
name: Failing hook
|
||||
description: |
|
||||
Failing Hook Description
|
||||
Longer description.
|
||||
entry: bin/hook.sh
|
||||
language: script
|
||||
files: .
|
||||
|
|
|
|||
|
|
@ -173,6 +173,26 @@ def test_run_all_hooks_failing(cap_out, store, repo_with_failing_hook):
|
|||
)
|
||||
|
||||
|
||||
def test_run_all_hooks_failing_verbose(cap_out, store, repo_with_failing_hook):
|
||||
_test_run(
|
||||
cap_out,
|
||||
store,
|
||||
repo_with_failing_hook,
|
||||
{'verbose': True},
|
||||
(
|
||||
b'Failing hook',
|
||||
b'Failed',
|
||||
b'hook id: failing_hook',
|
||||
b'description: |',
|
||||
b' Failing Hook Description',
|
||||
b' Longer description.',
|
||||
b'Fail\nfoo.py\n',
|
||||
),
|
||||
expected_ret=1,
|
||||
stage=True,
|
||||
)
|
||||
|
||||
|
||||
def test_arbitrary_bytes_hook(cap_out, store, tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'arbitrary_bytes_repo')
|
||||
with cwd(git_path):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue