template-dir/hooks/commit-msg in overcommit-0.19.0 vs template-dir/hooks/commit-msg in overcommit-0.20.0

- old
+ new

@@ -16,73 +16,42 @@ # in scripts without Overcommit running hooks if ENV['OVERCOMMIT_DISABLE'].to_i != 0 || ENV['OVERCOMMIT_DISABLED'].to_i != 0 exit end -# Required for Ruby 1.8 compatibility (for older OSX versions) -if RUBY_VERSION.split('.')[0..1] == %w[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') - puts 'Installing...' - 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 -- try running `gem install overcommit`' - exit 69 # EX_UNAVAILABLE - end - else - puts 'You chose not to install Overcommit' - puts "No hooks were run for '#{hook_type}'" - exit - end + puts 'This repository contains hooks installed by Overcommit, but the ' \ + "overcommit gem is not installed.\n" \ + 'Install it with `gem install overcommit`.' + exit end -if Gem::Version.new(Overcommit::VERSION) < Gem::Version.new('0.6.0') - puts "Installed version of Overcommit (#{Overcommit::VERSION}) is " \ - "incompatible with the installed hooks.\n" \ - 'Run `gem install overcommit && overcommit --install` to ensure ' \ - "you're up-to-date." - exit 64 # EX_USAGE -end - begin logger = Overcommit::Logger.new(STDOUT) # Ensure master hook is up-to-date installer = Overcommit::Installer.new(logger) - if installer.run(Overcommit::Utils.repo_root, :action => :update) + if installer.run(Overcommit::Utils.repo_root, action: :update) exec($0, *ARGV) # Execute the updated hook with all original arguments end config = Overcommit::ConfigurationLoader.load_repo_config - context = Overcommit::HookContext.create(hook_type, config, ARGV, STDIN) + context = Overcommit::HookContext.create(hook_type, config, ARGV) config.apply_environment!(context, ENV) - input = Overcommit::UserInput.new(STDIN) - printer = Overcommit::Printer.new(logger, context) - runner = Overcommit::HookRunner.new(config, logger, context, input, printer) + runner = Overcommit::HookRunner.new(config, logger, context, printer) status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR rescue Overcommit::Exceptions::ConfigurationError => error @@ -100,9 +69,11 @@ puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel rescue Overcommit::Exceptions::InvalidGitRepo => error puts error exit 64 # EX_USAGE +rescue Overcommit::Exceptions::InvalidHookSignature + exit 1 rescue => error puts error.message puts error.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE