@@ -119,6 +119,14 @@ 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+ select { |hook_name | gem_hook? ( hook_context , hook_name ) } .
127+ select { |hook_name | hook_enabled? ( hook_context , hook_name ) }
128+ end
129+
122130 # Returns the ad hoc hooks that have been enabled for a hook type.
123131 def enabled_ad_hoc_hooks ( hook_context )
124132 @hash [ hook_context . hook_class_name ] . keys .
@@ -259,6 +267,7 @@ def ad_hoc_hook?(hook_context, hook_name)
259267 # Ad hoc hooks are neither built-in nor have a plugin file written but
260268 # still have a `command` specified to be run
261269 !built_in_hook? ( hook_context , hook_name ) &&
270+ !gem_hook? ( hook_context , hook_name ) &&
262271 !plugin_hook? ( hook_context , hook_name ) &&
263272 ( ad_hoc_conf [ 'command' ] || ad_hoc_conf [ 'required_executable' ] )
264273 end
@@ -270,8 +279,18 @@ def built_in_hook?(hook_context, hook_name)
270279 hook_context . hook_type_name , "#{ hook_name } .rb" ) )
271280 end
272281
282+ def gem_hook? ( hook_context , hook_name )
283+ hook_name = Overcommit ::Utils . snake_case ( hook_name )
284+
285+ $LOAD_PATH. any? do |path |
286+ File . exist? ( File . join ( path , 'overcommit' , 'hook' ,
287+ hook_context . hook_type_name , "#{ hook_name } .rb" ) )
288+ end
289+ end
290+
273291 def hook_exists? ( hook_context , hook_name )
274292 built_in_hook? ( hook_context , hook_name ) ||
293+ gem_hook? ( hook_context , hook_name ) ||
275294 plugin_hook? ( hook_context , hook_name ) ||
276295 ad_hoc_hook? ( hook_context , hook_name )
277296 end
0 commit comments