Skip to content

Commit f1c5062

Browse files
committed
Don't display hook skip message unless hook would run
Previously, we would always display "Skipping <hook name>" when skipping via the `SKIP` environment variable, even if that hook would never have run (e.g. due to no applicable files). This would get annoying when specifying `SKIP=all` as it would display a large list of hooks that were "skipped"--most of which would never actually have run. Change the behavior to only display the message if the hook would have actually run. In the process, we were able to simplify some boolean expressions in `Hook#run?` and `HookRunner#run_hooks` as we realized they didn't need to be as complicated. Change-Id: I9f503b0d58bd6e3dd5c317f122c8694f3fb05072 Reviewed-on: http://gerrit.causes.com/45273 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent d1fda9a commit f1c5062

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Add `--run` flag which runs all configured pre-commit hooks against the
66
entire repository
77
* Fix installer to work with Overcommit hooks created via `GIT_TEMPLATE_DIR`
8+
* Fix hook runner to not display skip message unless hook would have actually
9+
run
810

911
## 0.19.0
1012
* Add `--no-pngout` flag for `image_optim` command on `:fail` message

lib/overcommit/hook/base.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def skip?
100100

101101
def run?
102102
enabled? &&
103-
(!skip? || required?) &&
104103
!(@config['requires_files'] && applicable_files.empty?)
105104
end
106105

lib/overcommit/hook_runner.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run
3636
attr_reader :log
3737

3838
def run_hooks
39-
if @hooks.any? { |hook| hook.run? || hook.skip? }
39+
if @hooks.any?(&:enabled?)
4040
@printer.start_run
4141

4242
interrupted = false
@@ -109,7 +109,8 @@ def should_skip?(hook)
109109
if hook.required?
110110
@printer.required_hook_not_skipped(hook)
111111
else
112-
@printer.hook_skipped(hook)
112+
# Tell user if hook was skipped only if it actually would have run
113+
@printer.hook_skipped(hook) if hook.run?
113114
return true
114115
end
115116
end

0 commit comments

Comments
 (0)