@@ -119,6 +119,15 @@ def enabled_builtin_hooks(hook_context)
119119 select { |hook_name | hook_enabled? ( hook_context , hook_name ) }
120120 end
121121
122+ # Returns the gem-provided hooks that have been enabled for a hook type.
123+ def enabled_gem_hooks ( hook_context )
124+ @hash [ hook_context . hook_class_name ] . keys .
125+ reject { |hook_name | hook_name == 'ALL' } .
126+ reject { |hook_name | built_in_hook? ( hook_context , hook_name ) } .
127+ select { |hook_name | gem_hook? ( hook_context , hook_name ) } .
128+ select { |hook_name | hook_enabled? ( hook_context , hook_name ) }
129+ end
130+
122131 # Returns the ad hoc hooks that have been enabled for a hook type.
123132 def enabled_ad_hoc_hooks ( hook_context )
124133 @hash [ hook_context . hook_class_name ] . keys .
@@ -259,6 +268,7 @@ def ad_hoc_hook?(hook_context, hook_name)
259268 # Ad hoc hooks are neither built-in nor have a plugin file written but
260269 # still have a `command` specified to be run
261270 !built_in_hook? ( hook_context , hook_name ) &&
271+ !gem_hook? ( hook_context , hook_name ) &&
262272 !plugin_hook? ( hook_context , hook_name ) &&
263273 ( ad_hoc_conf [ 'command' ] || ad_hoc_conf [ 'required_executable' ] )
264274 end
@@ -270,8 +280,18 @@ def built_in_hook?(hook_context, hook_name)
270280 hook_context . hook_type_name , "#{ hook_name } .rb" ) )
271281 end
272282
283+ def gem_hook? ( hook_context , hook_name )
284+ hook_name = Overcommit ::Utils . snake_case ( hook_name )
285+
286+ $LOAD_PATH. any? do |path |
287+ File . exist? ( File . join ( path , 'overcommit' , 'hook' ,
288+ hook_context . hook_type_name , "#{ hook_name } .rb" ) )
289+ end
290+ end
291+
273292 def hook_exists? ( hook_context , hook_name )
274293 built_in_hook? ( hook_context , hook_name ) ||
294+ gem_hook? ( hook_context , hook_name ) ||
275295 plugin_hook? ( hook_context , hook_name ) ||
276296 ad_hoc_hook? ( hook_context , hook_name )
277297 end
0 commit comments