Skip to content

Commit 284e899

Browse files
jawshooahsds
authored andcommitted
Fix tests in utils_spec and installing_overcommit_spec
Change-Id: Id4b0de5c08e7c82b3bfbcbe4d0b05de39ddd4bab Reviewed-on: http://gerrit.causes.com/46836 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent 3095d28 commit 284e899

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

spec/overcommit/utils_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@
108108
describe '.supported_hook_types' do
109109
subject { described_class.supported_hook_types }
110110

111-
it { should =~ %w[commit-msg pre-commit post-checkout] }
111+
it { should =~ %w[commit-msg pre-commit post-checkout post-merge] }
112112
end
113113

114114
describe '.supported_hook_type_classes' do
115115
subject { described_class.supported_hook_type_classes }
116116

117-
it { should =~ %w[CommitMsg PreCommit PostCheckout] }
117+
it { should =~ %w[CommitMsg PreCommit PostCheckout PostMerge] }
118118
end
119119

120120
describe '.execute' do

template-dir/hooks/post-merge

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env ruby
2+
3+
# Entrypoint for Overcommit hook integration. Installing Overcommit will result
4+
# in all of your git hooks being symlinked to this file, allowing the framework
5+
# to manage your hooks for you.
6+
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+
15+
# Allow hooks to be disabled via environment variable so git commands can be run
16+
# in scripts without Overcommit running hooks
17+
if ENV['OVERCOMMIT_DISABLE'].to_i != 0 || ENV['OVERCOMMIT_DISABLED'].to_i != 0
18+
exit
19+
end
20+
21+
hook_type = File.basename($0)
22+
if hook_type == 'overcommit-hook'
23+
puts "Don't run `overcommit-hook` directly; it is intended to be symlinked " \
24+
"by each hook in a repository's .git/hooks directory."
25+
exit 64 # EX_USAGE
26+
end
27+
28+
begin
29+
require 'overcommit'
30+
rescue LoadError
31+
puts 'This repository contains hooks installed by Overcommit, but the ' \
32+
"overcommit gem is not installed.\n" \
33+
'Install it with `gem install overcommit`.'
34+
exit
35+
end
36+
37+
begin
38+
logger = Overcommit::Logger.new(STDOUT)
39+
40+
# Ensure master hook is up-to-date
41+
installer = Overcommit::Installer.new(logger)
42+
if installer.run(Overcommit::Utils.repo_root, action: :update)
43+
exec($0, *ARGV) # Execute the updated hook with all original arguments
44+
end
45+
46+
config = Overcommit::ConfigurationLoader.load_repo_config
47+
48+
context = Overcommit::HookContext.create(hook_type, config, ARGV)
49+
config.apply_environment!(context, ENV)
50+
51+
printer = Overcommit::Printer.new(logger, context)
52+
runner = Overcommit::HookRunner.new(config, logger, context, printer)
53+
54+
status = runner.run
55+
56+
exit(status ? 0 : 65) # 65 = EX_DATAERR
57+
rescue Overcommit::Exceptions::ConfigurationError => error
58+
puts error
59+
exit 78 # EX_CONFIG
60+
rescue Overcommit::Exceptions::HookContextLoadError => error
61+
puts error
62+
puts 'Are you running an old version of Overcommit?'
63+
exit 69 # EX_UNAVAILABLE
64+
rescue Overcommit::Exceptions::HookSetupFailed,
65+
Overcommit::Exceptions::HookCleanupFailed => error
66+
puts error.message
67+
exit 74 # EX_IOERR
68+
rescue Overcommit::Exceptions::HookCancelled
69+
puts 'You cancelled the hook run'
70+
exit 130 # Ctrl-C cancel
71+
rescue Overcommit::Exceptions::InvalidGitRepo => error
72+
puts error
73+
exit 64 # EX_USAGE
74+
rescue Overcommit::Exceptions::InvalidHookSignature
75+
exit 1
76+
rescue => error
77+
puts error.message
78+
puts error.backtrace
79+
puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
80+
exit 70 # EX_SOFTWARE
81+
end

0 commit comments

Comments
 (0)