template-dir/hooks/commit-msg in overcommit-0.7.0 vs template-dir/hooks/commit-msg in overcommit-0.8.0

- old
+ new

@@ -3,31 +3,32 @@ # 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'] +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 " << + 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 ' << + 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`' @@ -39,35 +40,47 @@ exit end 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 ' << + 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) + exec $0 # Execute the updated hook + end + config = Overcommit::ConfigurationLoader.load_repo_config context = Overcommit::HookContext.create(hook_type, config, ARGV, STDIN) config.apply_environment!(context, ENV) - logger = Overcommit::Logger.new(STDOUT) - runner = Overcommit::HookRunner.new(config, logger, context) + input = Overcommit::UserInput.new(STDIN) + runner = Overcommit::HookRunner.new(config, logger, context, input) + 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::HookCancelled + puts 'You cancelled the hook run' + exit 1 rescue Overcommit::Exceptions::InvalidGitRepo => error puts error exit 64 # EX_USAGE rescue => error puts error.message