diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-11-01 13:46:13 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-11-01 13:46:37 +0100 |
commit | e76ad1dcb81e7be46f89b2fa4b848078a6318845 (patch) | |
tree | 730f33aeb9d5657795ec0a850a080d8de6263941 | |
parent | 634482d165ee5759206c42692a6857a588e63007 (diff) | |
download | gitlab-shell-e76ad1dcb81e7be46f89b2fa4b848078a6318845.tar.gz |
Refactor hook creation in GitlabProjects
-rw-r--r-- | lib/gitlab_projects.rb | 24 | ||||
-rw-r--r-- | spec/gitlab_projects_spec.rb | 5 |
2 files changed, 13 insertions, 16 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index bea5686..5bcf623 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -74,12 +74,14 @@ class GitlabProjects def add_project $logger.info "Adding project #{@project_name} at <#{full_path}>." FileUtils.mkdir_p(full_path, mode: 0770) - cmd = "cd #{full_path} && git init --bare && #{create_hooks_cmd}" - system(cmd) + cmd = "cd #{full_path} && git init --bare" + system(cmd) && create_hooks(full_path) end - def create_hooks_cmd - create_hooks_to(full_path) + 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) end def rm_project @@ -92,8 +94,8 @@ class GitlabProjects def import_project @source = ARGV.shift $logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>." - cmd = "cd #{repos_path} && git clone --bare #{@source} #{project_name} && #{create_hooks_cmd}" - system(cmd) + cmd = "cd #{repos_path} && git clone --bare #{@source} #{project_name}" + system(cmd) && create_hooks(full_path) end # Move repository from one directory to another @@ -154,8 +156,8 @@ class GitlabProjects end $logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>." - cmd = "cd #{namespaced_path} && git clone --bare #{full_path} && #{create_hooks_to(full_destination_path)}" - system(cmd) + cmd = "cd #{namespaced_path} && git clone --bare #{full_path}" + system(cmd) && create_hooks(full_destination_path) end def update_head @@ -178,10 +180,4 @@ class GitlabProjects $logger.info "Update head in project #{project_name} to <#{new_head}>." true end - - private - - def create_hooks_to(dest_path) - "ln -s #{File.join(ROOT_PATH, 'hooks', 'update')} #{dest_path}/hooks/update" - end end diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb index 6ff72ec..5c0b5b7 100644 --- a/spec/gitlab_projects_spec.rb +++ b/spec/gitlab_projects_spec.rb @@ -95,14 +95,15 @@ describe GitlabProjects do it "should create a directory" do gl_projects.stub(system: true) + gl_projects.stub(create_hooks: true) gl_projects.exec File.exists?(tmp_repo_path).should be_true end it "should receive valid cmd" do valid_cmd = "cd #{tmp_repo_path} && git init --bare" - valid_cmd << " && ln -s #{ROOT_PATH}/hooks/update #{tmp_repo_path}/hooks/update" - gl_projects.should_receive(:system).with(valid_cmd) + gl_projects.should_receive(:system).with(valid_cmd).and_return(true) + gl_projects.should_receive(:create_hooks).with(tmp_repo_path) gl_projects.exec end |