From 9a922f54935f8ba81a8a22038fbc6e2010571e15 Mon Sep 17 00:00:00 2001 From: Saverio Trioni Date: Tue, 11 Jul 2017 11:41:20 +0200 Subject: [PATCH] Allow hooks to be provided in separate gems When you have several repositories, and a set of common hooks, it is very complex to update all the hooks in each repository. With this change, "built in" hooks are searched in the whole load path, so the user can put one or more hooks in a gem and manage them consistently --- lib/overcommit/configuration.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/overcommit/configuration.rb b/lib/overcommit/configuration.rb index 25dba1cf..9de10816 100644 --- a/lib/overcommit/configuration.rb +++ b/lib/overcommit/configuration.rb @@ -1,5 +1,6 @@ require 'digest' require 'json' +require 'English' module Overcommit # Stores configuration for Overcommit and the hooks it runs. @@ -264,8 +265,10 @@ def ad_hoc_hook?(hook_context, hook_name) def built_in_hook?(hook_context, hook_name) hook_name = Overcommit::Utils.snake_case(hook_name) - File.exist?(File.join(Overcommit::HOME, 'lib', 'overcommit', 'hook', - hook_context.hook_type_name, "#{hook_name}.rb")) + $LOAD_PATH.any? do |dir| + File.exist?(File.join(dir, 'overcommit', 'hook', + hook_context.hook_type_name, "#{hook_name}.rb")) + end end def hook_exists?(hook_context, hook_name)