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:
helly25 2024-04-25 09:10:44 +00:00
parent 85fe18253f
commit 689f1203f7
No known key found for this signature in database
GPG key ID: 95B24A6EAE247816
4 changed files with 32 additions and 0 deletions

View file

@ -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: