summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-10-02 12:11:12 -0700
committerStan Hu <stanhu@gmail.com>2017-10-02 12:18:40 -0700
commit7ac4e2b2fc71b8c349248852070fc770188520fa (patch)
tree1fc3b1f4d8223b696cdba433818ec50ba1187c21
parentd62889dda7a74092ce070e51278c3ac637123d11 (diff)
downloadgitlab-ce-sh-import-repos-fix-9-5.tar.gz
Fix gitlab rake:import:repos tasksh-import-repos-fix-9-5
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
-rw-r--r--app/models/project.rb2
-rw-r--r--changelogs/unreleased/sh-import-repos-fix-9-5.yml4
-rw-r--r--lib/tasks/gitlab/import.rake3
-rw-r--r--spec/models/project_spec.rb11
-rw-r--r--spec/services/projects/create_service_spec.rb9
5 files changed, 28 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index c80e706234a..b2a75d2b332 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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")
diff --git a/changelogs/unreleased/sh-import-repos-fix-9-5.yml b/changelogs/unreleased/sh-import-repos-fix-9-5.yml
new file mode 100644
index 00000000000..082a0c7282d
--- /dev/null
+++ b/changelogs/unreleased/sh-import-repos-fix-9-5.yml
@@ -0,0 +1,4 @@
+---
+title: Fix gitlab rake:import:repos task
+merge_request:
+author:
diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake
index 48bd9139ce8..a7cb3242251 100644
--- a/lib/tasks/gitlab/import.rake
+++ b/lib/tasks/gitlab/import.rake
@@ -39,7 +39,8 @@ namespace :gitlab do
project_params = {
name: name,
- path: name
+ path: name,
+ skip_disk_validation: true
}
# find group namespace
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 98861c8c81a..f55d287445c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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,
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index dbf3c49c67d..95ff976e198 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -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