forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovercommit-hook
executable file
·75 lines (63 loc) · 2.33 KB
/
overcommit-hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env ruby
# Entrypoint for Overcommit hook integration. Installing Overcommit will result
# in all of your git hooks being symlinked to this file, allowing the framework
# to manage your hooks for you.
# Required for Ruby 1.8 compatibility (for older OSX versions)
if RUBY_VERSION.split('.')[0..1] == ['1', '8']
require 'rubygems'
end
hook_type = File.basename($0)
if hook_type == 'overcommit-hook'
puts "Don't run `overcommit-hook` directly; it is intended to be symlinked " <<
"by each hook in a repository's .git/hooks directory."
exit 64 # EX_USAGE
end
begin
require 'overcommit'
rescue LoadError
puts 'Overcommit is not installed. Install it to manage git hooks for ' <<
'this repository? (y/n)'
# If the hook isn't interactive, we need to map STDIN to keyboard manually
STDIN.reopen('/dev/tty') if STDIN.eof?
if (answer = gets) && answer.strip.downcase.start_with?('y')
if system('gem install overcommit')
Gem.clear_paths # Reset load paths so newly installed gem is found
require 'overcommit'
else
puts 'Unable to install Overcommit'
exit
end
else
puts 'You chose not to install Overcommit'
puts "No hooks were run for '#{hook_type}'"
exit
end
end
begin
hook_type_class = Overcommit::Utils.camel_case(hook_type)
config = Overcommit::ConfigurationLoader.load_repo_config
config.apply_environment!(hook_type_class, ENV)
# Ensure this script and all symlinks are always up-to-date (it's cheap to do)
Overcommit::Installer.new(Overcommit::Logger.silent).
run(Overcommit::Utils.repo_root, :action => :install)
context = Overcommit::HookContext.create(hook_type_class, config, ARGV, STDIN)
logger = Overcommit::Logger.new(STDOUT)
runner = Overcommit::HookRunner.new(config, logger, context)
status = runner.run
exit(status ? 0 : 65) # 65 = EX_DATAERR
rescue Overcommit::Exceptions::ConfigurationError => error
puts error
exit 78 # EX_CONFIG
rescue Overcommit::Exceptions::HookContextLoadError => error
puts error
puts 'Are you running an old version of Overcommit?'
exit 69 # EX_UNAVAILABLE
rescue Overcommit::Exceptions::InvalidGitRepo => error
puts error
exit 64 # EX_USAGE
rescue => error
puts error.message
puts error.backtrace
puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
exit 70 # EX_SOFTWARE
end