summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-10-02 17:34:08 +0000
committerRobert Speicher <robert@gitlab.com>2017-10-02 17:34:08 +0000
commit95f613837dca391a77eed9f948326b982c77d723 (patch)
tree579d270f764599115283e7e3d7dea17a3e26197c
parentfd8c56008fdadf45bd2ed1e0c50fbea51424a176 (diff)
parentbac29160302549c3c651991bf839b304a9e1c8b4 (diff)
downloadgitlab-ce-95f613837dca391a77eed9f948326b982c77d723.tar.gz
Merge branch 'sh-fix-import-repos' into 'master'
Fix gitlab-rake gitlab:import:repos task Closes #37682 See merge request gitlab-org/gitlab-ce!14597
-rw-r--r--app/models/project.rb6
-rw-r--r--changelogs/unreleased/sh-fix-import-repos.yml5
-rw-r--r--lib/gitlab/bare_repository_importer.rb3
-rw-r--r--spec/models/project_spec.rb11
-rw-r--r--spec/services/projects/create_service_spec.rb9
5 files changed, 31 insertions, 3 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index bb3f74c4b89..44d1190cc5b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -72,6 +72,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
@@ -227,7 +228,7 @@ class Project < ActiveRecord::Base
validates :import_url, importable_url: true, if: [:external_import?, :import_url_changed?]
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
- validate :can_create_repository?, on: [:create, :update], if: ->(project) { !project.persisted? || project.renamed? }
+ validate :check_repository_path_availability, on: [:create, :update], if: ->(project) { !project.persisted? || project.renamed? }
validate :avatar_type,
if: ->(project) { project.avatar.present? && project.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
@@ -1018,7 +1019,8 @@ class Project < ActiveRecord::Base
end
# Check if repository already exists on disk
- def can_create_repository?
+ def check_repository_path_availability
+ return true if skip_disk_validation
return false unless repository_storage_path
expires_full_path_cache # we need to clear cache to validate renames correctly
diff --git a/changelogs/unreleased/sh-fix-import-repos.yml b/changelogs/unreleased/sh-fix-import-repos.yml
new file mode 100644
index 00000000000..5764b3bdc01
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-import-repos.yml
@@ -0,0 +1,5 @@
+---
+title: Fix gitlab-rake gitlab:import:repos task failing
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/bare_repository_importer.rb b/lib/gitlab/bare_repository_importer.rb
index 9323bfc7fb2..1d98d187805 100644
--- a/lib/gitlab/bare_repository_importer.rb
+++ b/lib/gitlab/bare_repository_importer.rb
@@ -56,7 +56,8 @@ module Gitlab
name: project_path,
path: project_path,
repository_storage: storage_name,
- namespace_id: group&.id
+ namespace_id: group&.id,
+ skip_disk_validation: true
}
project = Projects::CreateService.new(user, project_params).execute
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 868a843ab0a..c94481d53c3 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2793,6 +2793,17 @@ describe Project do
end
end
+ describe '#check_repository_path_availability' 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.check_repository_path_availability).to be_truthy
+ end
+ end
+
describe '#latest_successful_pipeline_for_default_branch' do
let(:project) { build(:project) }
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index c2ec805ea99..35f0c85b0ec 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -209,6 +209,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