From f386d7a7b7f67ba8e77ee40ef6a3383d5206d0c1 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 16 May 2016 10:13:00 +0200 Subject: [PATCH] some changes based on MR feedback --- lib/gitlab/import_export/command_line_util.rb | 8 ++++++-- lib/gitlab/import_export/import_export_reader.rb | 1 + lib/gitlab/import_export/repo_bundler.rb | 2 +- lib/gitlab/import_export/wiki_repo_bundler.rb | 11 +++++------ .../gitlab/import_export/import_export_reader_spec.rb | 6 +++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb index c99b0d83b41..78664f076eb 100644 --- a/lib/gitlab/import_export/command_line_util.rb +++ b/lib/gitlab/import_export/command_line_util.rb @@ -9,11 +9,11 @@ module Gitlab untar_with_options(archive: archive, dir: dir, options: 'zxf') end - def git_bundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:) + def git_bundle(repo_path:, bundle_path:) execute(%W(#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all)) end - def git_unbundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:) + def git_unbundle(repo_path:, bundle_path:) execute(%W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path})) end @@ -31,6 +31,10 @@ module Gitlab _output, status = Gitlab::Popen.popen(cmd) status.zero? end + + def git_bin_path + Gitlab.config.git.bin_path + end end end end diff --git a/lib/gitlab/import_export/import_export_reader.rb b/lib/gitlab/import_export/import_export_reader.rb index 9aac0eae79a..25e13074e90 100644 --- a/lib/gitlab/import_export/import_export_reader.rb +++ b/lib/gitlab/import_export/import_export_reader.rb @@ -14,6 +14,7 @@ module Gitlab @attributes_parser.find_included(:project).merge(include: build_hash(@tree)) rescue => e @shared.error(e.message) + false end private diff --git a/lib/gitlab/import_export/repo_bundler.rb b/lib/gitlab/import_export/repo_bundler.rb index aff6e92be70..f41d5af4e53 100644 --- a/lib/gitlab/import_export/repo_bundler.rb +++ b/lib/gitlab/import_export/repo_bundler.rb @@ -5,7 +5,7 @@ module Gitlab attr_reader :full_path - def initialize(project: , shared: ) + def initialize(project:, shared:) @project = project @shared = shared end diff --git a/lib/gitlab/import_export/wiki_repo_bundler.rb b/lib/gitlab/import_export/wiki_repo_bundler.rb index a0000176bb5..016c640ae15 100644 --- a/lib/gitlab/import_export/wiki_repo_bundler.rb +++ b/lib/gitlab/import_export/wiki_repo_bundler.rb @@ -3,14 +3,13 @@ module Gitlab class WikiRepoBundler < RepoBundler def bundle @wiki = ProjectWiki.new(@project) - return true if !wiki? # it's okay to have no Wiki - @full_path = File.join(@shared.export_path, project_filename) - bundle_to_disk + return true unless wiki_repository_exists? # it's okay to have no Wiki + bundle_to_disk(File.join(@shared.export_path, project_filename)) end - def bundle_to_disk + def bundle_to_disk(full_path) FileUtils.mkdir_p(@shared.export_path) - git_bundle(repo_path: path_to_repo, bundle_path: @full_path) + git_bundle(repo_path: path_to_repo, bundle_path: full_path) rescue => e @shared.error(e.message) false @@ -26,7 +25,7 @@ module Gitlab @wiki.repository.path_to_repo end - def wiki? + def wiki_repository_exists? File.exists?(@wiki.repository.path_to_repo) && !@wiki.repository.empty? end end diff --git a/spec/lib/gitlab/import_export/import_export_reader_spec.rb b/spec/lib/gitlab/import_export/import_export_reader_spec.rb index 2fc9a39c68b..c4d03fecd54 100644 --- a/spec/lib/gitlab/import_export/import_export_reader_spec.rb +++ b/spec/lib/gitlab/import_export/import_export_reader_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::ImportExport::ImportExportReader do +describe Gitlab::ImportExport::ImportExportReader, lib: true do let(:shared) { Gitlab::ImportExport::Shared.new(relative_path:'') } let(:test_config) { 'spec/support/import_export/import_export.yml' } let(:project_tree_hash) do @@ -16,7 +16,7 @@ describe Gitlab::ImportExport::ImportExportReader do } end - it 'should generate hash from project tree config' do - expect(described_class.new(config: test_config, shared: shared).project_tree) =~ (project_tree_hash) + it 'generates hash from project tree config' do + expect(described_class.new(config: test_config, shared: shared).project_tree).to match(project_tree_hash) end end