diff --git a/app/services/projects/import_export/command_line_util.rb b/app/services/projects/import_export/command_line_util.rb index 7b0cc08763b606d279974030c09f04817454990c..3ca49e76c7fd041e372128ad69fe9e8025a064bd 100644 --- a/app/services/projects/import_export/command_line_util.rb +++ b/app/services/projects/import_export/command_line_util.rb @@ -6,6 +6,12 @@ module Projects _output, status = Gitlab::Popen.popen(cmd) status.zero? end + + def git_bundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:) + cmd = %W(#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all) + _output, status = Gitlab::Popen.popen(cmd) + status.zero? + end end end end diff --git a/app/services/projects/import_export/wiki_repo_bundler.rb b/app/services/projects/import_export/wiki_repo_bundler.rb new file mode 100644 index 0000000000000000000000000000000000000000..793c8efd142e5d4d29300380f621ed15f9aee7b4 --- /dev/null +++ b/app/services/projects/import_export/wiki_repo_bundler.rb @@ -0,0 +1,30 @@ +module Projects + module ImportExport + class WikiRepoBundler < RepoBundler + def bundle + @wiki = ProjectWiki.new(@project) + return false if !wiki? + @full_path = File.join(@export_path, project_filename) + bundle_to_disk + end + + def bundle_to_disk + FileUtils.mkdir_p(@export_path) + git_bundle(repo_path: path_to_repo, bundle_path: @full_path) + rescue + #TODO: handle error + false + end + + private + + def path_to_repo + @wiki.repository.path_to_repo + end + + def wiki? + File.exists?(@wiki.repository.path_to_repo) && !@wiki.repository.empty? + end + end + end +end diff --git a/spec/services/projects/import_export/wiki_repo_bundler_spec.rb b/spec/services/projects/import_export/wiki_repo_bundler_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..351419d061902044701e4cd330250194d7aafa98 --- /dev/null +++ b/spec/services/projects/import_export/wiki_repo_bundler_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Projects::ImportExport::WikiRepoBundler, services: true do + describe :bundle do + + let(:user) { create(:user) } + let!(:project) { create(:project, :public, name: 'searchable_project') } + let(:export_path) { "#{Dir::tmpdir}/project_tree_saver_spec" } + let(:shared) { Projects::ImportExport::Shared.new(relative_path: project.path_with_namespace) } + let(:wiki_bundler) { Projects::ImportExport::WikiRepoBundler.new(project: project, shared: shared) } + + before(:each) do + project.team << [user, :master] + allow_any_instance_of(Projects::ImportExport).to receive(:storage_path).and_return(export_path) + end + + after(:each) do + FileUtils.rm_rf(export_path) + end + + it 'bundles the repo successfully' do + expect(wiki_bundler.bundle).to be true + end + end +end