|
5 | 5 | # This script is used when restoring a GitLab backup. |
6 | 6 |
|
7 | 7 | require_relative '../lib/gitlab_init' |
8 | | -require File.join(ROOT_PATH, 'lib', 'gitlab_projects') |
9 | 8 | require File.join(ROOT_PATH, 'lib', 'gitlab_metrics') |
10 | 9 |
|
| 10 | +def create_hooks(path) |
| 11 | + global_hooks_directory = File.join(ROOT_PATH, 'hooks') |
| 12 | + local_hooks_directory = File.join(path, 'hooks') |
| 13 | + real_local_hooks_directory = :not_found |
| 14 | + |
| 15 | + begin |
| 16 | + real_local_hooks_directory = File.realpath(local_hooks_directory) |
| 17 | + rescue Errno::ENOENT |
| 18 | + # real_local_hooks_directory == :not_found |
| 19 | + end |
| 20 | + |
| 21 | + if real_local_hooks_directory != File.realpath(global_hooks_directory) |
| 22 | + if File.exist?(local_hooks_directory) |
| 23 | + $logger.info "Moving existing hooks directory and symlinking global hooks directory for #{path}." |
| 24 | + FileUtils.mv(local_hooks_directory, "#{local_hooks_directory}.old.#{Time.now.to_i}") |
| 25 | + end |
| 26 | + FileUtils.ln_sf(global_hooks_directory, local_hooks_directory) |
| 27 | + else |
| 28 | + $logger.info "Hooks already exist for #{path}." |
| 29 | + true |
| 30 | + end |
| 31 | +end |
| 32 | + |
11 | 33 | repository_storage_paths = ARGV |
12 | 34 |
|
13 | 35 | repository_storage_paths.each do |repo_path| |
14 | 36 | Dir["#{repo_path.chomp('/')}/**/*.git"].each do |repo| |
15 | 37 | begin |
16 | 38 | GitlabMetrics.measure('command-create-hooks') do |
17 | | - GitlabProjects.create_hooks(repo) |
| 39 | + create_hooks(repo) |
18 | 40 | end |
19 | 41 | rescue Errno::ENOENT |
20 | 42 | # The user must have deleted their repository. Ignore. |
|
0 commit comments