Commit 872c66e9 authored by Elan Ruusamäe's avatar Elan Ruusamäe Committed by Sean McGivern

avoid Dir.exists? duplication by moving the check to match_hook_files

parent d87c4b9c
...@@ -72,15 +72,11 @@ class GitlabCustomHook ...@@ -72,15 +72,11 @@ class GitlabCustomHook
# <repository>.git/custom_hooks/<hook_name>.d/* # <repository>.git/custom_hooks/<hook_name>.d/*
hook_path = File.join(@repo_path, 'custom_hooks', "#{hook_name}.d") hook_path = File.join(@repo_path, 'custom_hooks', "#{hook_name}.d")
if Dir.exist?(hook_path) hook_files += match_hook_files(hook_path)
hook_files += match_hook_files(hook_path)
end
# <repository>.git/hooks/<hook_name>.d/* # <repository>.git/hooks/<hook_name>.d/*
hook_path = File.join(@repo_path, 'hooks', "#{hook_name}.d") hook_path = File.join(@repo_path, 'hooks', "#{hook_name}.d")
if Dir.exist?(hook_path) hook_files += match_hook_files(hook_path)
hook_files += match_hook_files(hook_path)
end
hook_files hook_files
end end
...@@ -91,6 +87,8 @@ class GitlabCustomHook ...@@ -91,6 +87,8 @@ class GitlabCustomHook
# #
# the resulting list is sorted # the resulting list is sorted
def match_hook_files(path) def match_hook_files(path)
return [] unless Dir.exist?(path)
Dir["#{path}/*"].select do |f| Dir["#{path}/*"].select do |f|
!f.end_with?('~') && File.executable?(f) !f.end_with?('~') && File.executable?(f)
end.sort end.sort
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment