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

command_line_util.rb « import_export « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d03615f413e14713f8b1e2369b7b69f8b626fe36 (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
50
51
52
53
54
55
56
57
58
module Gitlab
  module ImportExport
    module CommandLineUtil
      def tar_czf(archive:, dir:)
        tar_with_options(archive: archive, dir: dir, options: 'czf')
      end

      def untar_zxf(archive:, dir:)
        untar_with_options(archive: archive, dir: dir, options: 'zxf')
      end

      def git_bundle(repo_path:, bundle_path:)
        execute(%W[#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all])
      end

      def git_unbundle(repo_path:, bundle_path:)
        execute(%W[#{git_bin_path} clone --bare #{bundle_path} #{repo_path}])
      end

      def git_restore_hooks
        execute(%W[#{Gitlab.config.gitlab_shell.path}/bin/create-hooks] + repository_storage_paths_args)
      end

      private

      def tar_with_options(archive:, dir:, options:)
        execute(%W[tar -#{options} #{archive} -C #{dir} .])
      end

      def untar_with_options(archive:, dir:, options:)
        execute(%W[tar -#{options} #{archive} -C #{dir}])
      end

      def execute(cmd)
        output, status = Gitlab::Popen.popen(cmd)
        @shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero?
        status.zero?
      end

      def git_bin_path
        Gitlab.config.git.bin_path
      end

      def copy_files(source, destination)
        # if we are copying files, create the destination folder
        destination_folder = File.file?(source) ? File.dirname(destination) : destination

        FileUtils.mkdir_p(destination_folder)
        FileUtils.copy_entry(source, destination)
        true
      end

      def repository_storage_paths_args
        Gitlab.config.repositories.storages.values
      end
    end
  end
end