2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class RepoSaver
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
attr_reader :project, :repository, :shared
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
def initialize(project:, shared:)
|
|
|
|
@project = project
|
|
|
|
@shared = shared
|
2019-12-21 20:55:43 +05:30
|
|
|
@repository = @project.repository
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2019-12-21 20:55:43 +05:30
|
|
|
return true unless repository_exists? # it's ok to have no repo
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
bundle_to_disk
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def repository_exists?
|
|
|
|
repository.exists? && !repository.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_full_path
|
|
|
|
File.join(shared.export_path, ImportExport.project_bundle_filename)
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def bundle_to_disk
|
2019-12-21 20:55:43 +05:30
|
|
|
mkdir_p(shared.export_path)
|
|
|
|
repository.bundle_to_disk(bundle_full_path)
|
2016-06-22 15:30:34 +05:30
|
|
|
rescue => e
|
2019-12-21 20:55:43 +05:30
|
|
|
shared.error(e)
|
2016-06-22 15:30:34 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|