Commit 01d2283e authored by Luke Duncalfe's avatar Luke Duncalfe

Support design repo in project namespace transfer

Allows design repositories to be moved when projects are transferred to
another namespace.

https://gitlab.com/gitlab-org/gitlab/issues/42410
parent 3b9944fc
...@@ -13,8 +13,6 @@ module Projects ...@@ -13,8 +13,6 @@ module Projects
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
TransferError = Class.new(StandardError) TransferError = Class.new(StandardError)
attr_reader :new_namespace
def execute(new_namespace) def execute(new_namespace)
@new_namespace = new_namespace @new_namespace = new_namespace
...@@ -39,6 +37,8 @@ module Projects ...@@ -39,6 +37,8 @@ module Projects
private private
attr_reader :old_path, :new_path, :new_namespace
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def transfer(project) def transfer(project)
@old_path = project.full_path @old_path = project.full_path
......
...@@ -16,7 +16,7 @@ module EE ...@@ -16,7 +16,7 @@ module EE
::Geo::RepositoryRenamedEventStore.new( ::Geo::RepositoryRenamedEventStore.new(
project, project,
old_path: project.path, old_path: project.path,
old_path_with_namespace: @old_path # rubocop:disable Gitlab/ModuleWithInstanceVariables old_path_with_namespace: old_path
).create! ).create!
end end
...@@ -29,9 +29,35 @@ module EE ...@@ -29,9 +29,35 @@ module EE
super super
end end
override :move_project_folders
def move_project_folders(project)
super
return if project.hashed_storage?(:repository)
move_repo_folder(old_design_repo_path, new_design_repo_path)
end
override :rollback_folder_move
def rollback_folder_move
super
return if project.hashed_storage?(:repository)
move_repo_folder(new_design_repo_path, old_design_repo_path)
end
def new_namespace_has_same_root?(project) def new_namespace_has_same_root?(project)
new_namespace.root_ancestor == project.namespace.root_ancestor new_namespace.root_ancestor == project.namespace.root_ancestor
end end
def old_design_repo_path
"#{old_path}#{EE::Gitlab::GlRepository::DESIGN.path_suffix}"
end
def new_design_repo_path
"#{new_path}#{EE::Gitlab::GlRepository::DESIGN.path_suffix}"
end
end end
end end
end end
---
title: Support moving the design repository of a project when the project is transferred
to a new namespace
merge_request: 23573
author:
type: changed
...@@ -5,9 +5,9 @@ require 'spec_helper' ...@@ -5,9 +5,9 @@ require 'spec_helper'
describe Projects::TransferService do describe Projects::TransferService do
include EE::GeoHelpers include EE::GeoHelpers
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
subject { described_class.new(project, user) } subject { described_class.new(project, user) }
...@@ -82,4 +82,82 @@ describe Projects::TransferService do ...@@ -82,4 +82,82 @@ describe Projects::TransferService do
end end
end end
end end
describe 'transferring a design repository' do
def design_repository
project.design_repository
end
it 'does not create a design repository' do
expect(subject.execute(group)).to be true
project.clear_memoization(:design_repository)
expect(design_repository.exists?).to be false
end
describe 'when the project has a design repository' do
let(:project_repo_path) { "#{project.path}#{EE::Gitlab::GlRepository::DESIGN.path_suffix}" }
let(:old_full_path) { "#{user.namespace.full_path}/#{project_repo_path}" }
let(:new_full_path) { "#{group.full_path}/#{project_repo_path}" }
context 'with legacy storage' do
let(:project) { create(:project, :repository, :legacy_storage, :design_repo, namespace: user.namespace) }
it 'moves the repository' do
expect(subject.execute(group)).to be true
project.clear_memoization(:design_repository)
expect(design_repository).to have_attributes(
disk_path: new_full_path,
full_path: new_full_path
)
end
it 'does not move the repository when an error occurs', :aggregate_failures do
allow(subject).to receive(:execute_system_hooks).and_raise('foo')
expect { subject.execute(group) }.to raise_error('foo')
project.clear_memoization(:design_repository)
expect(design_repository).to have_attributes(
disk_path: old_full_path,
full_path: old_full_path
)
end
end
context 'with hashed storage' do
let(:project) { create(:project, :repository, namespace: user.namespace) }
it 'does not move the repository' do
old_disk_path = design_repository.disk_path
expect(subject.execute(group)).to be true
project.clear_memoization(:design_repository)
expect(design_repository).to have_attributes(
disk_path: old_disk_path,
full_path: new_full_path
)
end
it 'does not move the repository when an error occurs' do
old_disk_path = design_repository.disk_path
allow(subject).to receive(:execute_system_hooks).and_raise('foo')
expect { subject.execute(group) }.to raise_error('foo')
project.clear_memoization(:design_repository)
expect(design_repository).to have_attributes(
disk_path: old_disk_path,
full_path: old_full_path
)
end
end
end
end
end end
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