debian-mirror-gitlab/lib/gitlab/git/bundle_file.rb

31 lines
650 B
Ruby
Raw Normal View History

2019-01-20 21:35:32 +05:30
# frozen_string_literal: true
module Gitlab
module Git
class BundleFile
# All git bundle files start with this string
#
# https://github.com/git/git/blob/v2.20.1/bundle.c#L15
MAGIC = "# v2 git bundle\n"
InvalidBundleError = Class.new(StandardError)
attr_reader :filename
def self.check!(filename)
new(filename).check!
end
def initialize(filename)
@filename = filename
end
def check!
data = File.open(filename, 'r') { |f| f.read(MAGIC.size) }
raise InvalidBundleError, 'Invalid bundle file' unless data == MAGIC
end
end
end
end