summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-16 15:09:28 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-16 15:09:28 +0000
commit63b6c78f585988f679a67b0710de2e1ad3b0d870 (patch)
tree64e3fa8b813938c0dcff242bb52c0dc5fbc600d7
parent27fe2ea53530709b9d51915d9cd95912c9be0a06 (diff)
parent4bd94c073e92d256b6d75f69cba5142eaff122ff (diff)
downloadgitlab-shell-63b6c78f585988f679a67b0710de2e1ad3b0d870.tar.gz
Merge branch 'symlink_hooks_directory' into 'master'
Symlink hooks directory See merge request !44
-rw-r--r--CHANGELOG1
-rw-r--r--lib/gitlab_projects.rb10
2 files changed, 7 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG
index daf6d11..30bddec 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ v2.0.0
- Replace raise with abort when checking path to prevent path exposure
- Handle invalid number of arguments on remote commands
- Replace update hook with pre-receive and post-receive hooks.
+ - Symlink the whole hooks directory
- Ignore missing repositories in create-hooks
- Connect to Redis via sockets by default
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index d6922c6..58bbd28 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}.old.#{Time.now.to_i}")
+ FileUtils.ln_s(GLOBAL_HOOKS_DIRECTORY, local_hooks_directory)
end
end