Skip to content

Commit cefbadc

Browse files
committed
Add global quiet option for silencing hook runs
Developers should have the ability to completely silence hook runs except in the case of warning or failure, if they so chose. Closes sds#357
1 parent 785887d commit cefbadc

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
for most use cases, but parallelized hook runs may be problematic. If someone
1111
from the community is willing to step up to support it, we'll gladly add it
1212
back.
13+
* Add global `quiet` option which silences all hook output except in the case
14+
of warning or error
1315

1416
## 0.32.0
1517

config/default.yml

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ gemfile: false
3939
# to the root of the repository.
4040
plugin_directory: '.git-hooks'
4141

42+
# Whether to hide hook output by default. This results in completely silent hook
43+
# runs except in the case of warning or failure.
44+
quiet: false
45+
4246
# Number of hooks that can be run concurrently. Typically this won't need to be
4347
# adjusted, but if you know that some of your hooks themselves use multiple
4448
# processors you can lower this value accordingly. You can define

lib/overcommit/cli.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def run_all
197197
context = Overcommit::HookContext.create('run-all', config, @arguments, empty_stdin)
198198
config.apply_environment!(context, ENV)
199199

200-
printer = Overcommit::Printer.new(log, context)
200+
printer = Overcommit::Printer.new(config, log, context)
201201
runner = Overcommit::HookRunner.new(config, log, context, printer)
202202

203203
status = runner.run

lib/overcommit/printer.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module Overcommit
88
class Printer
99
attr_reader :log
1010

11-
def initialize(logger, context)
11+
def initialize(config, logger, context)
12+
@config = config
1213
@log = logger
1314
@context = context
1415
@lock = Monitor.new # Need to use monitor so we can have re-entrant locks
@@ -17,7 +18,7 @@ def initialize(logger, context)
1718

1819
# Executed at the very beginning of running the collection of hooks.
1920
def start_run
20-
log.bold "Running #{hook_script_name} hooks"
21+
log.bold "Running #{hook_script_name} hooks" unless @config['quiet']
2122
end
2223

2324
def nothing_to_run
@@ -36,7 +37,7 @@ def required_hook_not_skipped(hook)
3637
def end_hook(hook, status, output)
3738
# Want to print the header for quiet hooks only if the result wasn't good
3839
# so that the user knows what failed
39-
print_header(hook) if !hook.quiet? || status != :pass
40+
print_header(hook) if (!hook.quiet? && !@config['quiet']) || status != :pass
4041

4142
print_result(hook, status, output)
4243
end
@@ -69,9 +70,11 @@ def run_warned
6970

7071
# Executed when no hooks failed by the end of the run.
7172
def run_succeeded
72-
log.newline
73-
log.success "✓ All #{hook_script_name} hooks passed"
74-
log.newline
73+
unless @config['quiet']
74+
log.newline
75+
log.success "✓ All #{hook_script_name} hooks passed"
76+
log.newline
77+
end
7578
end
7679

7780
private
@@ -83,10 +86,10 @@ def print_header(hook)
8386
log.partial hook_name
8487
end
8588

86-
def print_result(hook, status, output)
89+
def print_result(hook, status, output) # rubocop:disable Metrics/CyclomaticComplexity
8790
case status
8891
when :pass
89-
log.success 'OK' unless hook.quiet?
92+
log.success 'OK' unless @config['quiet'] || hook.quiet?
9093
when :warn
9194
log.warning 'WARNING'
9295
print_report(output, :bold_warning)

template-dir/hooks/overcommit-hook

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ begin
7373
context = Overcommit::HookContext.create(hook_type, config, ARGV, STDIN)
7474
config.apply_environment!(context, ENV)
7575

76-
printer = Overcommit::Printer.new(logger, context)
76+
printer = Overcommit::Printer.new(config, logger, context)
7777
runner = Overcommit::HookRunner.new(config, logger, context, printer)
7878

7979
status = runner.run

0 commit comments

Comments
 (0)