template-dir/hooks/pre-commit in overcommit-0.26.0 vs template-dir/hooks/pre-commit in overcommit-0.27.0

- old
+ new

@@ -23,21 +23,36 @@ 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 +# Check if Overcommit should invoke a Bundler context for loading gems +require 'yaml' +if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil + ENV['BUNDLE_GEMFILE'] = gemfile + require 'bundler/setup' +end + begin require 'overcommit' rescue LoadError - puts 'This repository contains hooks installed by Overcommit, but the ' \ - "overcommit gem is not installed.\n" \ - 'Install it with `gem install overcommit`.' - exit + if gemfile + puts 'You have specified the `gemfile` option in your Overcommit ' \ + 'configuration but have not added the `overcommit` gem to ' \ + "#{gemfile}." + else + puts 'This repository contains hooks installed by Overcommit, but the ' \ + "`overcommit` gem is not installed.\n" \ + 'Install it with `gem install overcommit`.' + end + + exit 64 # EX_USAGE end begin logger = Overcommit::Logger.new(STDOUT) + Overcommit::Utils.log = logger # Ensure master hook is up-to-date installer = Overcommit::Installer.new(logger) if installer.run(Overcommit::Utils.repo_root, action: :update) exec($0, *ARGV) # Execute the updated hook with all original arguments @@ -59,9 +74,14 @@ 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::HookLoadError, + Overcommit::Exceptions::InvalidHookDefinition => error + puts error.message + puts error.backtrace + exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, Overcommit::Exceptions::HookCleanupFailed => error puts error.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled