gitlab-org--gitlab-foss/lib/gitlab/import_export/command_line_util.rb

59 lines
1.7 KiB
Ruby
Raw Normal View History

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
2016-05-16 08:13:00 +00:00
def git_bundle(repo_path:, bundle_path:)
execute(%W(#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all))
end
2016-03-08 17:17:57 +00:00
2016-05-16 08:13:00 +00:00
def git_unbundle(repo_path:, bundle_path:)
execute(%W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path}))
2016-03-08 17:17:57 +00:00
end
def git_restore_hooks
execute(%W(#{Gitlab.config.gitlab_shell.path}/bin/create-hooks) + repository_storage_paths_args)
end
2016-05-06 12:39:57 +00:00
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)
2016-07-06 08:29:31 +00:00
output, status = Gitlab::Popen.popen(cmd)
2016-07-07 07:49:46 +00:00
@shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero?
status.zero?
end
2016-05-16 08:13:00 +00:00
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