summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElan Ruusamäe <glen@delfi.ee>2016-11-16 02:12:07 +0200
committerSean McGivern <sean@gitlab.com>2016-12-01 11:40:11 +0000
commit872c66e977b3041e0c18543d2e00a255e8e89e41 (patch)
tree1347ab48525fdd2fe0a6af686c95118758935668
parentd87c4b9c0d3aed4a23d74f340ece2c4bff83101b (diff)
downloadgitlab-shell-872c66e977b3041e0c18543d2e00a255e8e89e41.tar.gz
avoid Dir.exists? duplication by moving the check to match_hook_files
-rw-r--r--lib/gitlab_custom_hook.rb10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb
index 6265ec1..a48ad12 100644
--- a/lib/gitlab_custom_hook.rb
+++ b/lib/gitlab_custom_hook.rb
@@ -72,15 +72,11 @@ class GitlabCustomHook
# <repository>.git/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)
- end
+ hook_files += match_hook_files(hook_path)
# <repository>.git/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)
- end
+ hook_files += match_hook_files(hook_path)
hook_files
end
@@ -91,6 +87,8 @@ class GitlabCustomHook
#
# the resulting list is sorted
def match_hook_files(path)
+ return [] unless Dir.exist?(path)
+
Dir["#{path}/*"].select do |f|
!f.end_with?('~') && File.executable?(f)
end.sort