Commit 7ac4e2b2 authored by Stan Hu's avatar Stan Hu

Fix gitlab rake:import:repos task

This backports !14597 for the 9.5.x branch.

Because of a change in GitLab 9.5.4 to prevent users from assuming control of
a repository already on disk, the import task broke. Imports would fail with
the message, "There is already a repository with that name on disk".

This change skips the validation when the import is done from the
command-line.

Closes #37682
parent d62889dd
......@@ -77,6 +77,7 @@ class Project < ActiveRecord::Base
attr_accessor :old_path_with_namespace
attr_accessor :template_name
attr_writer :pipeline_status
attr_accessor :skip_disk_validation
alias_attribute :title, :name
......@@ -993,6 +994,7 @@ class Project < ActiveRecord::Base
# Check if repository already exists on disk
def can_create_repository?
return true if skip_disk_validation
return false unless repository_storage_path
if gitlab_shell.exists?(repository_storage_path, "#{build_full_path}.git")
......
---
title: Fix gitlab rake:import:repos task
merge_request:
author:
......@@ -39,7 +39,8 @@ namespace :gitlab do
project_params = {
name: name,
path: name
path: name,
skip_disk_validation: true
}
# find group namespace
......
......@@ -1650,6 +1650,17 @@ describe Project do
end
end
describe '#can_create_repository?' do
let(:project) { build(:project) }
it 'skips gitlab-shell exists?' do
project.skip_disk_validation = true
expect(project.gitlab_shell).not_to receive(:exists?)
expect(project.can_create_repository?).to be_truthy
end
end
describe '#latest_successful_builds_for' do
def create_pipeline(status = 'success')
create(:ci_pipeline, project: project,
......
......@@ -208,6 +208,15 @@ describe Projects::CreateService, '#execute' do
end
end
context 'when skip_disk_validation is used' do
it 'sets the project attribute' do
opts[:skip_disk_validation] = true
project = create_project(user, opts)
expect(project.skip_disk_validation).to be_truthy
end
end
def create_project(user, opts)
Projects::CreateService.new(user, opts).execute
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