BigW Consortium Gitlab

command_line_util.rb 1.02 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

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
15

16
      def git_unbundle(repo_path:, bundle_path:)
17
        execute(%W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path}))
18
      end
19

James Lopez committed
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)
31 32 33
        _output, status = Gitlab::Popen.popen(cmd)
        status.zero?
      end
34 35 36 37

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