2018-11-17 00:37:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-14 14:57:25 +00:00
|
|
|
module Gitlab
|
2016-03-08 11:35:37 +00:00
|
|
|
module ImportExport
|
2016-06-03 10:56:29 +00:00
|
|
|
class RepoSaver
|
2016-04-14 14:57:25 +00:00
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
2016-03-08 11:35:37 +00:00
|
|
|
|
2019-09-27 09:06:26 +00:00
|
|
|
attr_reader :project, :repository, :shared
|
2016-03-08 11:35:37 +00:00
|
|
|
|
2016-05-16 08:13:00 +00:00
|
|
|
def initialize(project:, shared:)
|
2016-03-08 11:35:37 +00:00
|
|
|
@project = project
|
2016-05-10 15:15:20 +00:00
|
|
|
@shared = shared
|
2019-09-27 09:06:26 +00:00
|
|
|
@repository = @project.repository
|
2016-03-08 11:35:37 +00:00
|
|
|
end
|
|
|
|
|
2016-06-03 10:56:29 +00:00
|
|
|
def save
|
2019-09-27 09:06:26 +00:00
|
|
|
return true unless repository_exists? # it's ok to have no repo
|
2016-06-14 08:15:20 +00:00
|
|
|
|
2016-03-08 11:35:37 +00:00
|
|
|
bundle_to_disk
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-27 09:06:26 +00:00
|
|
|
def repository_exists?
|
|
|
|
repository.exists? && !repository.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_full_path
|
|
|
|
File.join(shared.export_path, ImportExport.project_bundle_filename)
|
|
|
|
end
|
|
|
|
|
2016-03-08 11:35:37 +00:00
|
|
|
def bundle_to_disk
|
2019-09-27 09:06:26 +00:00
|
|
|
mkdir_p(shared.export_path)
|
|
|
|
repository.bundle_to_disk(bundle_full_path)
|
2016-05-10 15:15:20 +00:00
|
|
|
rescue => e
|
2019-09-27 09:06:26 +00:00
|
|
|
shared.error(e)
|
2016-03-08 11:35:37 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|