WIP - added wiki repo bundler

This commit is contained in:
James Lopez 2016-03-08 18:17:57 +01:00
parent 556cafa44e
commit 99d87d8698
3 changed files with 61 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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