From 89d88f7ebc97377d4df96aed076ebc971183fdec Mon Sep 17 00:00:00 2001
From: Peter Cock
Date: Sat, 15 Aug 2020 13:54:57 +0100
Subject: [PATCH] Implement quiet mode, silent on skipped hooks
---
pre_commit/commands/run.py | 42 +++++++++++++++++++++-----------------
pre_commit/main.py | 4 ++++
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
index 1f28c8c7..5c3baff6 100644
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -137,35 +137,38 @@ def _run_single_hook(
diff_before: bytes,
verbose: bool,
use_color: bool,
+ quiet: bool,
) -> Tuple[bool, bytes]:
filenames = classifier.filenames_for_hook(hook)
if hook.id in skips or hook.alias in skips:
- output.write(
- _full_msg(
- start=hook.name,
- end_msg=SKIPPED,
- end_color=color.YELLOW,
- use_color=use_color,
- cols=cols,
- ),
- )
+ if not quiet:
+ output.write(
+ _full_msg(
+ start=hook.name,
+ end_msg=SKIPPED,
+ end_color=color.YELLOW,
+ use_color=use_color,
+ cols=cols,
+ ),
+ )
duration = None
retcode = 0
diff_after = diff_before
files_modified = False
out = b''
elif not filenames and not hook.always_run:
- output.write(
- _full_msg(
- start=hook.name,
- postfix=NO_FILES,
- end_msg=SKIPPED,
- end_color=color.TURQUOISE,
- use_color=use_color,
- cols=cols,
- ),
- )
+ if not quiet:
+ output.write(
+ _full_msg(
+ start=hook.name,
+ postfix=NO_FILES,
+ end_msg=SKIPPED,
+ end_color=color.TURQUOISE,
+ use_color=use_color,
+ cols=cols,
+ ),
+ )
duration = None
retcode = 0
diff_after = diff_before
@@ -272,6 +275,7 @@ def _run_hooks(
current_retval, prior_diff = _run_single_hook(
classifier, hook, skips, cols, prior_diff,
verbose=args.verbose, use_color=args.color,
+ quiet=False if args.verbose else args.quiet,
)
retval |= current_retval
if retval and config['fail_fast']:
diff --git a/pre_commit/main.py b/pre_commit/main.py
index 86479607..60891711 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -81,6 +81,10 @@ def _add_hook_type_option(parser: argparse.ArgumentParser) -> None:
def _add_run_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument('hook', nargs='?', help='A single hook-id to run')
parser.add_argument('--verbose', '-v', action='store_true', default=False)
+ parser.add_argument(
+ '--quiet', '-q', action='store_true', default=False,
+ help='Enable quiet mode (verbose mode overrides this).',
+ )
mutex_group = parser.add_mutually_exclusive_group(required=False)
mutex_group.add_argument(
'--all-files', '-a', action='store_true', default=False,