diff options
-rw-r--r-- | lib/gitlab/import_export/importer.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/import_export/wiki_restorer.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/wiki_restorer_spec.rb | 8 |
3 files changed, 20 insertions, 9 deletions
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb index 938a7f963af..a00795f553e 100644 --- a/lib/gitlab/import_export/importer.rb +++ b/lib/gitlab/import_export/importer.rb @@ -52,7 +52,8 @@ module Gitlab def wiki_restorer Gitlab::ImportExport::WikiRestorer.new(path_to_bundle: wiki_repo_path, shared: @shared, - project: ProjectWiki.new(project_tree.restored_project)) + project: ProjectWiki.new(project_tree.restored_project), + wiki_enabled: @project.wiki_enabled?) end def uploads_restorer diff --git a/lib/gitlab/import_export/wiki_restorer.rb b/lib/gitlab/import_export/wiki_restorer.rb index 263ff187c8a..b4fdab512f6 100644 --- a/lib/gitlab/import_export/wiki_restorer.rb +++ b/lib/gitlab/import_export/wiki_restorer.rb @@ -1,14 +1,24 @@ module Gitlab module ImportExport class WikiRestorer < RepoRestorer + def initialize(project:, shared:, path_to_bundle:, wiki_enabled:) + @project = project + @path_to_bundle = path_to_bundle + @shared = shared + @wiki_enabled = wiki_enabled + end + def restore - unless File.exist?(@path_to_bundle) - # Creates an empty wiki if it does not exist in the bundle - @project.wiki - end + @project.wiki if create_empty_wiki? super end + + private + + def create_empty_wiki? + !File.exist?(@path_to_bundle) && @wiki_enabled + end end end end diff --git a/spec/lib/gitlab/import_export/wiki_restorer_spec.rb b/spec/lib/gitlab/import_export/wiki_restorer_spec.rb index a7a32f13e32..9409c08e280 100644 --- a/spec/lib/gitlab/import_export/wiki_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/wiki_restorer_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe Gitlab::ImportExport::WikiRestorer do describe 'restore a wiki Git repo' do - let(:user) { create(:user) } let!(:project_with_wiki) { create(:project, :wiki_repo) } let!(:project_without_wiki) { create(:project) } let!(:project) { create(:project) } @@ -13,7 +12,8 @@ describe Gitlab::ImportExport::WikiRestorer do let(:restorer) do described_class.new(path_to_bundle: bundle_path, shared: shared, - project: project.wiki) + project: project.wiki, + wiki_enabled: true) end before do @@ -24,8 +24,8 @@ describe Gitlab::ImportExport::WikiRestorer do after do FileUtils.rm_rf(export_path) - FileUtils.rm_rf(project_with_wiki.wiki.repository.path_to_repo) - FileUtils.rm_rf(project.wiki.repository.path_to_repo) + Gitlab::Shell.new.remove_repository(project_with_wiki.wiki.repository_storage_path, project_with_wiki.wiki.disk_path) + Gitlab::Shell.new.remove_repository(project.wiki.repository_storage_path, project.wiki.disk_path) end it 'restores the wiki repo successfully' do |