Commit c109b621 authored by Stan Hu's avatar Stan Hu

Merge branch 'vzagorodny-fix-forks-dev-seeds' into 'master'

Fix broken development DB seeds for forks

Closes gitlab-foss#63471

See merge request gitlab-org/gitlab!16849
parents e3bd2bff 1bd4d7cc
...@@ -51,7 +51,8 @@ module Projects ...@@ -51,7 +51,8 @@ module Projects
# been instantiated to avoid ActiveRecord trying to create it when # been instantiated to avoid ActiveRecord trying to create it when
# initializing the project, as that would cause a foreign key constraint # initializing the project, as that would cause a foreign key constraint
# exception. # exception.
relations_block: -> (project) { build_fork_network_member(project) } relations_block: -> (project) { build_fork_network_member(project) },
skip_disk_validation: skip_disk_validation
} }
if @project.avatar.present? && @project.avatar.image? if @project.avatar.present? && @project.avatar.image?
...@@ -110,6 +111,10 @@ module Projects ...@@ -110,6 +111,10 @@ module Projects
@target_namespace ||= @params[:namespace] || current_user.namespace @target_namespace ||= @params[:namespace] || current_user.namespace
end end
def skip_disk_validation
@skip_disk_validation ||= @params[:skip_disk_validation] || false
end
def allowed_visibility_level def allowed_visibility_level
target_level = [@project.visibility_level, target_namespace.visibility_level].min target_level = [@project.visibility_level, target_namespace.visibility_level].min
......
...@@ -6,11 +6,16 @@ Sidekiq::Testing.inline! do ...@@ -6,11 +6,16 @@ Sidekiq::Testing.inline! do
source_project = Project.public_only.sample source_project = Project.public_only.sample
## ##
# 04_project.rb might not have created a public project because # 03_project.rb might not have created a public project because
# we use randomized approach (e.g. `Array#sample`). # we use randomized approach (e.g. `Array#sample`).
return unless source_project return unless source_project
fork_project = Projects::ForkService.new(source_project, user, namespace: user.namespace).execute fork_project = Projects::ForkService.new(
source_project,
user,
namespace: user.namespace,
skip_disk_validation: true
).execute
if fork_project.valid? if fork_project.valid?
print '.' print '.'
......
...@@ -119,6 +119,7 @@ describe Projects::ForkService do ...@@ -119,6 +119,7 @@ describe Projects::ForkService do
context 'repository in legacy storage already exists' do context 'repository in legacy storage already exists' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:params) { { namespace: @to_user.namespace } }
before do before do
stub_application_setting(hashed_storage_enabled: false) stub_application_setting(hashed_storage_enabled: false)
...@@ -129,12 +130,21 @@ describe Projects::ForkService do ...@@ -129,12 +130,21 @@ describe Projects::ForkService do
gitlab_shell.remove_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}") gitlab_shell.remove_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}")
end end
subject { fork_project(@from_project, @to_user, params) }
it 'does not allow creation' do it 'does not allow creation' do
to_project = fork_project(@from_project, @to_user, namespace: @to_user.namespace) expect(subject).not_to be_persisted
expect(subject.errors.messages).to have_key(:base)
expect(subject.errors.messages[:base].first).to match('There is already a repository with that name on disk')
end
expect(to_project).not_to be_persisted context 'when repository disk validation is explicitly skipped' do
expect(to_project.errors.messages).to have_key(:base) let(:params) { super().merge(skip_disk_validation: true) }
expect(to_project.errors.messages[:base].first).to match('There is already a repository with that name on disk')
it 'allows fork project creation' do
expect(subject).to be_persisted
expect(subject.errors.messages).to be_empty
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