Commit 21cfad24 authored by James Lopez's avatar James Lopez

Merge branches 'feature/project-export-ui-experimental' and...

Merge branches 'feature/project-export-ui-experimental' and 'feature/project-import' of gitlab.com:gitlab-org/gitlab-ce into feature/project-export-ui-experimental
parents e14d1051 92f4bde4
...@@ -4,8 +4,10 @@ module Projects ...@@ -4,8 +4,10 @@ module Projects
def execute(options = {}) def execute(options = {})
@shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work')) @shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work'))
# TODO handle errors
save_project_tree save_project_tree
bundle_repo bundle_repo
bundle_wiki_repo
save_all save_all
end end
...@@ -19,6 +21,10 @@ module Projects ...@@ -19,6 +21,10 @@ module Projects
Gitlab::ImportExport::RepoBundler.new(project: project, shared: @shared).bundle Gitlab::ImportExport::RepoBundler.new(project: project, shared: @shared).bundle
end end
def bundle_wiki_repo
Gitlab::ImportExport::WikiRepoBundler.new(project: project, shared: @shared).bundle
end
def save_all def save_all
Gitlab::ImportExport::Saver.save(storage_path: @shared.export_path) Gitlab::ImportExport::Saver.save(storage_path: @shared.export_path)
end end
......
...@@ -23,6 +23,12 @@ module Gitlab ...@@ -23,6 +23,12 @@ module Gitlab
status.zero? status.zero?
end 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:) def tar_with_options(archive:, dir:, options:)
cmd = %W(tar -#{options} #{archive} -C #{dir} .) cmd = %W(tar -#{options} #{archive} -C #{dir} .)
_output, status = Gitlab::Popen.popen(cmd) _output, status = Gitlab::Popen.popen(cmd)
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
def execute def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file, storage_path: storage_path) 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 end
private private
...@@ -29,7 +29,11 @@ module Gitlab ...@@ -29,7 +29,11 @@ module Gitlab
end end
def restore_repo 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 end
def storage_path def storage_path
...@@ -39,6 +43,14 @@ module Gitlab ...@@ -39,6 +43,14 @@ module Gitlab
def path_with_namespace def path_with_namespace
File.join(@namespace.path, @project_path) File.join(@namespace.path, @project_path)
end 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 end
end end
...@@ -20,9 +20,8 @@ module Gitlab ...@@ -20,9 +20,8 @@ module Gitlab
def bundle_to_disk def bundle_to_disk
FileUtils.mkdir_p(@export_path) FileUtils.mkdir_p(@export_path)
tar_cf(archive: full_path, dir: path_to_repo) git_bundle(repo_path: path_to_repo, bundle_path: @full_path)
rescue rescue
#TODO: handle error
false false
end end
......
...@@ -3,19 +3,18 @@ module Gitlab ...@@ -3,19 +3,18 @@ module Gitlab
class RepoRestorer class RepoRestorer
include Gitlab::ImportExport::CommandLineUtil include Gitlab::ImportExport::CommandLineUtil
def initialize(project:, path:) def initialize(project:, path_to_bundle: )
@project = project @project = project
# TODO remove magic keyword and move it to a shared config @path_to_bundle = path_to_bundle
@path = File.join(path, 'project.bundle')
end end
def restore def restore
return false unless File.exists?(@path) return true unless File.exists?(@path)
# Move repos dir to 'repositories.old' dir
FileUtils.mkdir_p(repos_path) FileUtils.mkdir_p(repos_path)
FileUtils.mkdir_p(path_to_repo) 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 end
private private
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
class WikiRepoBundler < RepoBundler class WikiRepoBundler < RepoBundler
def bundle def bundle
@wiki = ProjectWiki.new(@project) @wiki = ProjectWiki.new(@project)
return false if !wiki? return true if !wiki? # it's okay to have no Wiki
@full_path = File.join(@export_path, project_filename) @full_path = File.join(@export_path, project_filename)
bundle_to_disk bundle_to_disk
end end
...@@ -12,7 +12,6 @@ module Gitlab ...@@ -12,7 +12,6 @@ module Gitlab
FileUtils.mkdir_p(@export_path) FileUtils.mkdir_p(@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 rescue
#TODO: handle error
false false
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment