blob: 8384a436fcc75f73719560b60b87451c12e29c34 (
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
|
# 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
|