use git bundle in import and add wiki repo to import

This commit is contained in:
James Lopez 2016-05-05 12:39:18 +02:00
parent 43488d277e
commit 92f4bde427
3 changed files with 25 additions and 8 deletions

View File

@ -23,6 +23,12 @@ module Gitlab
status.zero?
end
def git_unbundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:)
cmd = %W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path})
_output, status = Gitlab::Popen.popen(cmd)
status.zero?
end
def tar_with_options(archive:, dir:, options:)
cmd = %W(tar -#{options} #{archive} -C #{dir} .)
_output, status = Gitlab::Popen.popen(cmd)

View File

@ -15,7 +15,7 @@ module Gitlab
def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file, storage_path: storage_path)
project_tree.project if [restore_project_tree, restore_repo].all?
project_tree.project if [restore_project_tree, restore_repo, restore_wiki_repo].all?
end
private
@ -29,7 +29,11 @@ module Gitlab
end
def restore_repo
Gitlab::ImportExport::RepoRestorer.new(path: storage_path, project: project_tree.project).restore
Gitlab::ImportExport::RepoRestorer.new(path: repo_path, project: project_tree.project).restore
end
def restore_wiki_repo
Gitlab::ImportExport::RepoRestorer.new(path: wiki_repo_path, project: project_tree.project).restore
end
def storage_path
@ -39,6 +43,14 @@ module Gitlab
def path_with_namespace
File.join(@namespace.path, @project_path)
end
def repo_path
File.join('storage_path', 'project.bundle')
end
def wiki_repo_path
File.join('storage_path', 'project.wiki.bundle')
end
end
end
end

View File

@ -3,19 +3,18 @@ module Gitlab
class RepoRestorer
include Gitlab::ImportExport::CommandLineUtil
def initialize(project:, path:)
def initialize(project:, path_to_bundle: )
@project = project
# TODO remove magic keyword and move it to a shared config
@path = File.join(path, 'project.bundle')
@path_to_bundle = path_to_bundle
end
def restore
return false unless File.exists?(@path)
# Move repos dir to 'repositories.old' dir
return true unless File.exists?(@path)
FileUtils.mkdir_p(repos_path)
FileUtils.mkdir_p(path_to_repo)
untar_xf(archive: @path, dir: path_to_repo)
git_unbundle(git_bin_path: Gitlab.config.git.bin_path, repo_path: path_to_repo, bundle_path: @path_to_bundle)
end
private