BigW Consortium Gitlab

Commit 028a317d by James Lopez Committed by Tiago Botelho

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
parent 8b4f3084
...@@ -102,6 +102,10 @@ class Repository ...@@ -102,6 +102,10 @@ class Repository
"#<#{self.class.name}:#{@disk_path}>" "#<#{self.class.name}:#{@disk_path}>"
end end
def create_hooks
Gitlab::Git::Repository.create_hooks(path_to_repo, Gitlab.config.gitlab_shell.hooks_path)
end
def commit(ref = 'HEAD') def commit(ref = 'HEAD')
return nil unless exists? return nil unless exists?
return ref if ref.is_a?(::Commit) return ref if ref.is_a?(::Commit)
......
---
title: Fix hooks not being set up properly for bare import Rake task
merge_request:
author:
type: fixed
...@@ -61,6 +61,9 @@ module Gitlab ...@@ -61,6 +61,9 @@ module Gitlab
if project.persisted? && mv_repo(project) if project.persisted? && mv_repo(project)
log " * Created #{project.name} (#{project_full_path})".color(:green) log " * Created #{project.name} (#{project_full_path})".color(:green)
project.write_repository_config
project.repository.create_hooks
ProjectCacheWorker.perform_async(project.id) ProjectCacheWorker.perform_async(project.id)
else else
log " * Failed trying to create #{project.name} (#{project_full_path})".color(:red) log " * Failed trying to create #{project.name} (#{project_full_path})".color(:red)
......
...@@ -68,14 +68,24 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do ...@@ -68,14 +68,24 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
expect(Project.find_by_full_path(project_path)).not_to be_nil expect(Project.find_by_full_path(project_path)).not_to be_nil
end end
it 'creates the Git repo in disk' do it 'does not schedule an import' do
FileUtils.mkdir_p(File.join(base_dir, "#{project_path}.git")) 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 importer.create_project_if_needed
project = Project.find_by_full_path(project_path) 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 end
context 'hashed storage enabled' do context 'hashed storage enabled' do
......
...@@ -358,6 +358,28 @@ describe Repository do ...@@ -358,6 +358,28 @@ describe Repository do
end end
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 describe "#create_dir" do
it "commits a change that creates a new directory" do it "commits a change that creates a new directory" do
expect do expect do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment