2016-06-22 15:30:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class RepoRestorer
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
def initialize(project:, shared:, path_to_bundle:)
|
2016-06-22 15:30:34 +05:30
|
|
|
@project = project
|
|
|
|
@path_to_bundle = path_to_bundle
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
2016-08-24 12:49:21 +05:30
|
|
|
return true unless File.exist?(@path_to_bundle)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
FileUtils.mkdir_p(path_to_repo)
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
git_unbundle(repo_path: path_to_repo, bundle_path: @path_to_bundle) && repo_restore_hooks
|
2016-06-22 15:30:34 +05:30
|
|
|
rescue => e
|
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def path_to_repo
|
|
|
|
@project.repository.path_to_repo
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
def repo_restore_hooks
|
|
|
|
return true if wiki?
|
|
|
|
|
|
|
|
git_restore_hooks
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def wiki?
|
2016-08-24 12:49:21 +05:30
|
|
|
@project.class.name == 'ProjectWiki'
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|