summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@gitlab.com>2017-12-11 08:47:50 +0000
committerLUKE BENNETT <lbennett@gitlab.com>2017-12-13 13:40:04 +0000
commit0f04fa2859d436e78de2f6d30e01b2134a094103 (patch)
treeffc5fac83e27940bc1783d656c7b491ddd7d0ef4
parent0d09108ad2bb2605d0ec2b50ac7d3f46db3ee728 (diff)
downloadgitlab-ce-0f04fa2859d436e78de2f6d30e01b2134a094103.tar.gz
Merge branch 'sh-fix-import-rake-task' into 'master'
Fix gitlab:import:repos Rake task moving repositories into the wrong location Closes #40765 See merge request gitlab-org/gitlab-ce!15823 (cherry picked from commit 7694ae887885c66eb633d3f78eac3128a08dc978) 78f7c3c8 Fix gitlab:import:repos Rake task moving repositories into the wrong location e8cced80 Fix failing importer test case on MySQL due to missing trailing slash in root path 917a112e Simplify normalizing of paths 86661a3a Use build instead of create in importer spec f1eaab7b Remove the need for destroy and add a comment in the spec
-rw-r--r--changelogs/unreleased/sh-fix-import-rake-task.yml5
-rw-r--r--lib/gitlab/bare_repository_import/importer.rb1
-rw-r--r--lib/gitlab/bare_repository_import/repository.rb2
-rw-r--r--spec/lib/gitlab/bare_repository_import/importer_spec.rb17
-rw-r--r--spec/lib/gitlab/bare_repository_import/repository_spec.rb7
5 files changed, 32 insertions, 0 deletions
diff --git a/changelogs/unreleased/sh-fix-import-rake-task.yml b/changelogs/unreleased/sh-fix-import-rake-task.yml
new file mode 100644
index 00000000000..9cd6d7e4a72
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-import-rake-task.yml
@@ -0,0 +1,5 @@
+---
+title: Fix gitlab:import:repos Rake task moving repositories into the wrong location
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/bare_repository_import/importer.rb b/lib/gitlab/bare_repository_import/importer.rb
index 196de667805..298409d8b5a 100644
--- a/lib/gitlab/bare_repository_import/importer.rb
+++ b/lib/gitlab/bare_repository_import/importer.rb
@@ -55,6 +55,7 @@ module Gitlab
name: project_name,
path: project_name,
skip_disk_validation: true,
+ import_type: 'gitlab_project',
namespace_id: group&.id).execute
if project.persisted? && mv_repo(project)
diff --git a/lib/gitlab/bare_repository_import/repository.rb b/lib/gitlab/bare_repository_import/repository.rb
index 8574ac6eb30..fa7891c8dcc 100644
--- a/lib/gitlab/bare_repository_import/repository.rb
+++ b/lib/gitlab/bare_repository_import/repository.rb
@@ -7,6 +7,8 @@ module Gitlab
@root_path = root_path
@repo_path = repo_path
+ @root_path << '/' unless root_path.ends_with?('/')
+
# Split path into 'all/the/namespaces' and 'project_name'
@group_path, _, @project_name = repo_relative_path.rpartition('/')
end
diff --git a/spec/lib/gitlab/bare_repository_import/importer_spec.rb b/spec/lib/gitlab/bare_repository_import/importer_spec.rb
index 7f3bf5fc41c..8a83e446935 100644
--- a/spec/lib/gitlab/bare_repository_import/importer_spec.rb
+++ b/spec/lib/gitlab/bare_repository_import/importer_spec.rb
@@ -132,6 +132,23 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
expect(File).to exist(File.join(project.repository_storage_path, project.disk_path + '.git'))
end
+
+ it 'moves an existing project to the correct path' do
+ # This is a quick way to get a valid repository instead of copying an
+ # existing one. Since it's not persisted, the importer will try to
+ # create the project.
+ project = build(:project, :repository)
+ original_commit_count = project.repository.commit_count
+
+ bare_repo = Gitlab::BareRepositoryImport::Repository.new(project.repository_storage_path, project.repository.path)
+ gitlab_importer = described_class.new(admin, bare_repo)
+
+ expect(gitlab_importer).to receive(:create_project).and_call_original
+
+ new_project = gitlab_importer.create_project_if_needed
+
+ expect(new_project.repository.commit_count).to eq(original_commit_count)
+ end
end
context 'with Wiki' do
diff --git a/spec/lib/gitlab/bare_repository_import/repository_spec.rb b/spec/lib/gitlab/bare_repository_import/repository_spec.rb
index 2db737f5fb6..61b73abcba4 100644
--- a/spec/lib/gitlab/bare_repository_import/repository_spec.rb
+++ b/spec/lib/gitlab/bare_repository_import/repository_spec.rb
@@ -46,6 +46,13 @@ describe ::Gitlab::BareRepositoryImport::Repository do
describe '#project_full_path' do
it 'returns the project full path' do
expect(project_repo_path.repo_path).to eq('/full/path/to/repo.git')
+ expect(project_repo_path.project_full_path).to eq('to/repo')
+ end
+
+ it 'with no trailing slash in the root path' do
+ repo_path = described_class.new('/full/path', '/full/path/to/repo.git')
+
+ expect(repo_path.project_full_path).to eq('to/repo')
end
end
end