diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-26 11:03:01 +0000 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-26 11:03:01 +0000 |
| commit | 704b08adbd16a1d7f610478d8f77cca36a1981b5 (patch) | |
| tree | 2b1ee9d230ae4c5e76617e7979c174b5015accfb | |
| parent | 56e216f33ca0db21336cc8dc1f7e09a834267772 (diff) | |
| parent | 3bd2b660ff550e3eddea5b4b113ee79cf66e0f7f (diff) | |
| download | gitlab-shell-704b08adbd16a1d7f610478d8f77cca36a1981b5.tar.gz | |
Merge branch 'create_hooks' into 'master'
Add bin/create-hooks command for backup restores
This solves the problem that `support/rewrite-hooks.sh` assumes that the gitlab-shell is installed in `/home/git/gitlab-shell`, which does not hold for omnibus-gitlab.
| -rwxr-xr-x | bin/create-hooks | 12 | ||||
| -rw-r--r-- | lib/gitlab_projects.rb | 18 | ||||
| -rw-r--r-- | spec/gitlab_projects_spec.rb | 4 | ||||
| -rwxr-xr-x | support/rewrite-hooks.sh | 29 |
4 files changed, 26 insertions, 37 deletions
diff --git a/bin/create-hooks b/bin/create-hooks new file mode 100755 index 0000000..d6f07c7 --- /dev/null +++ b/bin/create-hooks @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby + +# Recreate GitLab hooks in the Git repositories managed by GitLab. +# +# This script is used when restoring a GitLab backup. + +require_relative '../lib/gitlab_init' +require File.join(ROOT_PATH, 'lib', 'gitlab_projects') + +Dir["#{GitlabConfig.new.repos_path}/*/*.git"].each do |repo| + GitlabProjects.create_hooks(repo) +end diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index fec204c..a0063aa 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -16,6 +16,12 @@ class GitlabProjects # Ex /home/git/repositories/test.git attr_reader :full_path + def self.create_hooks(path) + hook = File.join(path, 'hooks', 'update') + File.delete(hook) if File.exists?(hook) + File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook) + end + def initialize @command = ARGV.shift @project_name = ARGV.shift @@ -74,13 +80,7 @@ class GitlabProjects $logger.info "Adding project #{@project_name} at <#{full_path}>." FileUtils.mkdir_p(full_path, mode: 0770) cmd = %W(git --git-dir=#{full_path} init --bare) - system(*cmd) && create_hooks(full_path) - end - - def create_hooks(path) - hook = File.join(path, 'hooks', 'update') - File.delete(hook) if File.exists?(hook) - File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook) + system(*cmd) && self.class.create_hooks(full_path) end def rm_project @@ -94,7 +94,7 @@ class GitlabProjects @source = ARGV.shift $logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>." cmd = %W(git clone --bare -- #{@source} #{full_path}) - system(*cmd) && create_hooks(full_path) + system(*cmd) && self.class.create_hooks(full_path) end # Move repository from one directory to another @@ -156,7 +156,7 @@ class GitlabProjects $logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>." cmd = %W(git clone --bare -- #{full_path} #{full_destination_path}) - system(*cmd) && create_hooks(full_destination_path) + system(*cmd) && self.class.create_hooks(full_destination_path) end def update_head diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb index bbe27e2..4341ca5 100644 --- a/spec/gitlab_projects_spec.rb +++ b/spec/gitlab_projects_spec.rb @@ -95,7 +95,7 @@ describe GitlabProjects do it "should create a directory" do gl_projects.stub(system: true) - gl_projects.stub(create_hooks: true) + GitlabProjects.stub(create_hooks: true) gl_projects.exec File.exists?(tmp_repo_path).should be_true end @@ -103,7 +103,7 @@ describe GitlabProjects do it "should receive valid cmd" do valid_cmd = ['git', "--git-dir=#{tmp_repo_path}", 'init', '--bare'] gl_projects.should_receive(:system).with(*valid_cmd).and_return(true) - gl_projects.should_receive(:create_hooks).with(tmp_repo_path) + GitlabProjects.should_receive(:create_hooks).with(tmp_repo_path) gl_projects.exec end diff --git a/support/rewrite-hooks.sh b/support/rewrite-hooks.sh index 3c96b6f..585eaeb 100755 --- a/support/rewrite-hooks.sh +++ b/support/rewrite-hooks.sh @@ -1,28 +1,5 @@ #!/bin/bash +# This script is deprecated. Use bin/create-hooks instead. -# $1 is an optional argument specifying the location of the repositories directory. -# Defaults to /home/git/repositories if not provided - -home_dir="/home/git" -src=${1:-"$home_dir/repositories"} - -function create_link_in { - ln -s -f "$home_dir/gitlab-shell/hooks/update" "$1/hooks/update" -} - -for dir in `ls "$src/"` -do - if [ -d "$src/$dir" ]; then - if [[ "$dir" =~ ^.*\.git$ ]] - then - create_link_in "$src/$dir" - else - for subdir in `ls "$src/$dir/"` - do - if [ -d "$src/$dir/$subdir" ] && [[ "$subdir" =~ ^.*\.git$ ]]; then - create_link_in "$src/$dir/$subdir" - fi - done - fi - fi -done +gitlab_shell_dir="$(cd $(dirname $0) && pwd)/.." +exec ${gitlab_shell_dir}/bin/create-hooks |
