From db81327b909e2674312e53c97c742c35f432c5bd Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 16 Sep 2014 15:05:03 +0200 Subject: Symlink the whole hooks directory --- lib/gitlab_projects.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/gitlab_projects.rb') diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index d6922c6..a216d8b 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -5,6 +5,8 @@ require_relative 'gitlab_config' require_relative 'gitlab_logger' class GitlabProjects + GLOBAL_HOOKS_DIRECTORY = File.join(ROOT_PATH, 'hooks') + # Project name is a directory name for repository with .git at the end # It may be namespaced or not. Like repo.git or gitlab/repo.git attr_reader :project_name @@ -18,10 +20,10 @@ class GitlabProjects attr_reader :full_path def self.create_hooks(path) - %w(pre-receive post-receive).each do |hook_name| - hook = File.join(path, 'hooks', hook_name) - File.delete(hook) if File.exists?(hook) - File.symlink(File.join(ROOT_PATH, 'hooks', hook_name), hook) + local_hooks_directory = File.join(path, 'hooks') + unless File.realpath(local_hooks_directory) == File.realpath(GLOBAL_HOOKS_DIRECTORY) + FileUtils.mv(local_hooks_directory, "#{local_hooks_directory}.#{Time.now.to_i}") + FileUtils.ln_s(GLOBAL_HOOKS_DIRECTORY, local_hooks_directory) end end -- cgit v1.2.1