diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-08-12 14:59:13 +0200 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-08-12 14:59:13 +0200 |
commit | a10d47232778e093f7810d8011f887e5453f9007 (patch) | |
tree | 86785917cd97bbe295a171975793c2c8fd9a8dbf /lib/gitlab_projects.rb | |
parent | c31e6165016e4f12483b4c328a62493adac1bcac (diff) | |
download | gitlab-shell-create-hooks-broken-symlink.tar.gz |
Handle broken symlinks in create-hookscreate-hooks-broken-symlink
If a repository contained a broken symlink named 'hooks', this would
raise ENOENT in lib/gitlab_projects.rb, which got ignored in
bin/create-hooks. This commit fixes that by making sure we handle
broken symlinks in lib/gitlab_projects.rb.
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index 11f3820..8bf000d 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -21,11 +21,19 @@ class GitlabProjects def self.create_hooks(path) local_hooks_directory = File.join(path, 'hooks') + real_local_hooks_directory = :not_found + begin + real_local_hooks_directory = File.realpath(local_hooks_directory) + rescue Errno::ENOENT + # real_local_hooks_directory == :not_found + end - if File.realpath(local_hooks_directory) != File.realpath(GLOBAL_HOOKS_DIRECTORY) - $logger.info "Moving existing hooks directory and symlinking global hooks directory for #{path}." - FileUtils.mv(local_hooks_directory, "#{local_hooks_directory}.old.#{Time.now.to_i}") - FileUtils.ln_s(GLOBAL_HOOKS_DIRECTORY, local_hooks_directory) + if real_local_hooks_directory != File.realpath(GLOBAL_HOOKS_DIRECTORY) + if File.exist?(local_hooks_directory) + $logger.info "Moving existing hooks directory and symlinking global hooks directory for #{path}." + FileUtils.mv(local_hooks_directory, "#{local_hooks_directory}.old.#{Time.now.to_i}") + end + FileUtils.ln_sf(GLOBAL_HOOKS_DIRECTORY, local_hooks_directory) else $logger.info "Hooks already exist for #{path}." true |