Skip to content

Commit 444231d

Browse files
committed
Prevent early interrupt from displaying stack trace
If a user pressed Ctrl-C _really_ early in a hook run, they would get an ugly stack trace since we don't set up a signal handler until we load the Overcommit code. Add a signal handler so that these early interrupts can be gracefully caught. Change-Id: I184cdcb3a76802095508d33af01b63f694cfbb83 Reviewed-on: http://gerrit.causes.com/41195 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent c45c725 commit 444231d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Handle edge case where if a file was created in the working directory by a
1111
separate process in between the working tree being reset and the stash being
1212
applied, the hook runner would silently fail
13+
* Prevent stack traces from appearing during early interrupt before Overcommit
14+
has loaded its code
1315

1416
## 0.15.0
1517

template-dir/hooks/overcommit-hook

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
# in all of your git hooks being symlinked to this file, allowing the framework
55
# to manage your hooks for you.
66

7+
# Prevent a Ruby stack trace from appearing when we interrupt the hook.
8+
# Note that this will be overridden when Overcommit is loaded, since the
9+
# InterruptHandler will redefine the trap at that time.
10+
Signal.trap('INT') do
11+
puts 'Hook run interrupted'
12+
exit 130
13+
end
14+
715
# Required for Ruby 1.8 compatibility (for older OSX versions)
816
if RUBY_VERSION.split('.')[0..1] == %w[1 8]
917
require 'rubygems'
@@ -84,7 +92,7 @@ rescue Overcommit::Exceptions::HookSetupFailed,
8492
exit 74 # EX_IOERR
8593
rescue Overcommit::Exceptions::HookCancelled
8694
puts 'You cancelled the hook run'
87-
exit 1
95+
exit 130 # Ctrl-C cancel
8896
rescue Overcommit::Exceptions::InvalidGitRepo => error
8997
puts error
9098
exit 64 # EX_USAGE

0 commit comments

Comments
 (0)