command_line_util.rb 1.1 KB
Newer Older
1
module Gitlab
2 3
  module ImportExport
    module CommandLineUtil
4 5
      def tar_czf(archive:, dir:)
        tar_with_options(archive: archive, dir: dir, options: 'czf')
6 7
      end

8 9 10 11
      def untar_zxf(archive:, dir:)
        untar_with_options(archive: archive, dir: dir, options: 'zxf')
      end

J
James Lopez 已提交
12
      def git_bundle(repo_path:, bundle_path:)
13
        execute(%W(#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all))
14
      end
J
James Lopez 已提交
15

J
James Lopez 已提交
16
      def git_unbundle(repo_path:, bundle_path:)
17
        execute(%W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path}))
J
James Lopez 已提交
18
      end
19

J
James Lopez 已提交
20 21
      private

22
      def tar_with_options(archive:, dir:, options:)
23
        execute(%W(tar -#{options} #{archive} -C #{dir} .))
24
      end
25 26

      def untar_with_options(archive:, dir:, options:)
27 28 29 30
        execute(%W(tar -#{options} #{archive} -C #{dir}))
      end

      def execute(cmd)
J
James Lopez 已提交
31
        output, status = Gitlab::Popen.popen(cmd)
32
        @shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero?
33 34
        status.zero?
      end
J
James Lopez 已提交
35 36 37 38

      def git_bin_path
        Gitlab.config.git.bin_path
      end
39 40 41
    end
  end
end