2016-04-15 16:14:28 +00:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class RepoRestorer
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
2016-07-18 09:02:07 +00:00
|
|
|
def initialize(project:, shared:, path_to_bundle:)
|
2016-04-15 16:14:28 +00:00
|
|
|
@project = project
|
2016-05-05 10:39:18 +00:00
|
|
|
@path_to_bundle = path_to_bundle
|
2016-05-11 15:22:45 +00:00
|
|
|
@shared = shared
|
2016-04-15 16:14:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
2016-07-18 09:02:07 +00:00
|
|
|
return true unless File.exist?(@path_to_bundle)
|
2016-04-15 16:14:28 +00:00
|
|
|
|
|
|
|
FileUtils.mkdir_p(path_to_repo)
|
2016-05-05 10:39:18 +00:00
|
|
|
|
2016-07-28 14:28:12 +00:00
|
|
|
git_unbundle(repo_path: path_to_repo, bundle_path: @path_to_bundle) && repo_restore_hooks
|
2016-05-11 15:22:45 +00:00
|
|
|
rescue => e
|
2016-05-13 10:33:13 +00:00
|
|
|
@shared.error(e)
|
2016-05-05 11:19:41 +00:00
|
|
|
false
|
2016-04-15 16:14:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def repos_path
|
|
|
|
Gitlab.config.gitlab_shell.repos_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def path_to_repo
|
|
|
|
@project.repository.path_to_repo
|
|
|
|
end
|
2016-07-28 14:28:12 +00:00
|
|
|
|
|
|
|
def repo_restore_hooks
|
|
|
|
return true if wiki?
|
|
|
|
|
|
|
|
git_restore_hooks
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki?
|
|
|
|
@project.class.name == 'ProjectWiki'
|
|
|
|
end
|
2016-04-15 16:14:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|