Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repo_saver.rb « import_export « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0fdd0722b65af65e3a0f71d6163b8a8cfb0c7dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

module Gitlab
  module ImportExport
    class RepoSaver
      include Gitlab::ImportExport::CommandLineUtil

      attr_reader :exportable, :shared

      def initialize(exportable:, shared:)
        @exportable = exportable
        @shared = shared
      end

      def save
        return true unless repository_exists? # it's ok to have no repo

        bundle_to_disk
      end

      def repository
        @repository ||= @exportable.repository
      end

      private

      def repository_exists?
        repository.exists? && !repository.empty?
      end

      def bundle_full_path
        File.join(shared.export_path, bundle_filename)
      end

      def bundle_filename
        ::Gitlab::ImportExport.project_bundle_filename
      end

      def bundle_to_disk
        mkdir_p(File.dirname(bundle_full_path))

        repository.bundle_to_disk(bundle_full_path)
      rescue => e
        shared.error(e)
        false
      end
    end
  end
end