Skip to content

Commit

Permalink
Add global quiet option for silencing hook runs
Browse files Browse the repository at this point in the history
Developers should have the ability to completely silence hook runs
except in the case of warning or failure, if they so chose.

Closes #357
  • Loading branch information
sds committed Apr 6, 2016
1 parent 785887d commit cefbadc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
for most use cases, but parallelized hook runs may be problematic. If someone
from the community is willing to step up to support it, we'll gladly add it
back.
* Add global `quiet` option which silences all hook output except in the case
of warning or error

## 0.32.0

Expand Down
4 changes: 4 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ gemfile: false
# to the root of the repository.
plugin_directory: '.git-hooks'

# Whether to hide hook output by default. This results in completely silent hook
# runs except in the case of warning or failure.
quiet: false

# Number of hooks that can be run concurrently. Typically this won't need to be
# adjusted, but if you know that some of your hooks themselves use multiple
# processors you can lower this value accordingly. You can define
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def run_all
context = Overcommit::HookContext.create('run-all', config, @arguments, empty_stdin)
config.apply_environment!(context, ENV)

printer = Overcommit::Printer.new(log, context)
printer = Overcommit::Printer.new(config, log, context)
runner = Overcommit::HookRunner.new(config, log, context, printer)

status = runner.run
Expand Down
19 changes: 11 additions & 8 deletions lib/overcommit/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Overcommit
class Printer
attr_reader :log

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

# Executed at the very beginning of running the collection of hooks.
def start_run
log.bold "Running #{hook_script_name} hooks"
log.bold "Running #{hook_script_name} hooks" unless @config['quiet']
end

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

print_result(hook, status, output)
end
Expand Down Expand Up @@ -69,9 +70,11 @@ def run_warned

# Executed when no hooks failed by the end of the run.
def run_succeeded
log.newline
log.success "✓ All #{hook_script_name} hooks passed"
log.newline
unless @config['quiet']
log.newline
log.success "✓ All #{hook_script_name} hooks passed"
log.newline
end
end

private
Expand All @@ -83,10 +86,10 @@ def print_header(hook)
log.partial hook_name
end

def print_result(hook, status, output)
def print_result(hook, status, output) # rubocop:disable Metrics/CyclomaticComplexity
case status
when :pass
log.success 'OK' unless hook.quiet?
log.success 'OK' unless @config['quiet'] || hook.quiet?
when :warn
log.warning 'WARNING'
print_report(output, :bold_warning)
Expand Down
2 changes: 1 addition & 1 deletion template-dir/hooks/overcommit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ begin
context = Overcommit::HookContext.create(hook_type, config, ARGV, STDIN)
config.apply_environment!(context, ENV)

printer = Overcommit::Printer.new(logger, context)
printer = Overcommit::Printer.new(config, logger, context)
runner = Overcommit::HookRunner.new(config, logger, context, printer)

status = runner.run
Expand Down

0 comments on commit cefbadc

Please sign in to comment.