diff options
author | James Lopez <james@gitlab.com> | 2018-01-10 08:20:47 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-01-19 14:37:31 +0000 |
commit | 028a317d9f98c0fa520d95234dc2635af7f7c6e5 (patch) | |
tree | c1b117ce186eecdac37a18fb7d622e4c07a2ad06 | |
parent | 8b4f3084fab962d78907f588e7f61c9a486964b5 (diff) | |
download | gitlab-ce-028a317d9f98c0fa520d95234dc2635af7f7c6e5.tar.gz |
Merge branch 'sh-fix-bare-import-hooks' into 'master'
Fix hooks not being set up properly for bare import Rake task
Closes #41739
See merge request gitlab-org/gitlab-ce!16280
-rw-r--r-- | app/models/repository.rb | 4 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-bare-import-hooks.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/bare_repository_import/importer.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/bare_repository_import/importer_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 22 |
5 files changed, 47 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index d1ae3304e4a..929ba97b4a1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -102,6 +102,10 @@ class Repository "#<#{self.class.name}:#{@disk_path}>" end + def create_hooks + Gitlab::Git::Repository.create_hooks(path_to_repo, Gitlab.config.gitlab_shell.hooks_path) + end + def commit(ref = 'HEAD') return nil unless exists? return ref if ref.is_a?(::Commit) diff --git a/changelogs/unreleased/sh-fix-bare-import-hooks.yml b/changelogs/unreleased/sh-fix-bare-import-hooks.yml new file mode 100644 index 00000000000..deb6c62f738 --- /dev/null +++ b/changelogs/unreleased/sh-fix-bare-import-hooks.yml @@ -0,0 +1,5 @@ +--- +title: Fix hooks not being set up properly for bare import Rake task +merge_request: +author: +type: fixed diff --git a/lib/gitlab/bare_repository_import/importer.rb b/lib/gitlab/bare_repository_import/importer.rb index 298409d8b5a..cce2bf5f18f 100644 --- a/lib/gitlab/bare_repository_import/importer.rb +++ b/lib/gitlab/bare_repository_import/importer.rb @@ -61,6 +61,9 @@ module Gitlab if project.persisted? && mv_repo(project) log " * Created #{project.name} (#{project_full_path})".color(:green) + project.write_repository_config + project.repository.create_hooks + ProjectCacheWorker.perform_async(project.id) else log " * Failed trying to create #{project.name} (#{project_full_path})".color(:red) diff --git a/spec/lib/gitlab/bare_repository_import/importer_spec.rb b/spec/lib/gitlab/bare_repository_import/importer_spec.rb index 8a83e446935..1fb7d91c392 100644 --- a/spec/lib/gitlab/bare_repository_import/importer_spec.rb +++ b/spec/lib/gitlab/bare_repository_import/importer_spec.rb @@ -68,14 +68,24 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do expect(Project.find_by_full_path(project_path)).not_to be_nil end - it 'creates the Git repo in disk' do - FileUtils.mkdir_p(File.join(base_dir, "#{project_path}.git")) + it 'does not schedule an import' do + expect_any_instance_of(Project).not_to receive(:import_schedule) + + importer.create_project_if_needed + end + + it 'creates the Git repo on disk with the proper symlink for hooks' do + create_bare_repository("#{project_path}.git") importer.create_project_if_needed project = Project.find_by_full_path(project_path) + repo_path = File.join(project.repository_storage_path, project.disk_path + '.git') + hook_path = File.join(repo_path, 'hooks') - expect(File).to exist(File.join(project.repository_storage_path, project.disk_path + '.git')) + expect(File).to exist(repo_path) + expect(File.symlink?(hook_path)).to be true + expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path) end context 'hashed storage enabled' do diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 358bc3dfb94..90415b34aeb 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -358,6 +358,28 @@ describe Repository do end end + describe '#create_hooks' do + let(:hook_path) { File.join(repository.path_to_repo, 'hooks') } + + it 'symlinks the global hooks directory' do + repository.create_hooks + + expect(File.symlink?(hook_path)).to be true + expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path) + end + + it 'replaces existing symlink with the right directory' do + FileUtils.mkdir_p(hook_path) + + expect(File.symlink?(hook_path)).to be false + + repository.create_hooks + + expect(File.symlink?(hook_path)).to be true + expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path) + end + end + describe "#create_dir" do it "commits a change that creates a new directory" do expect do |