debian-mirror-gitlab/spec/support/unpack-gitlab-git-test

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
991 B
Text
Raw Normal View History

2017-09-10 17:25:29 +05:30
#!/usr/bin/env ruby
2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'fileutils'
2019-12-26 22:10:19 +05:30
REPO = 'spec/support/gitlab-git-test.git'
2017-09-10 17:25:29 +05:30
PACK_DIR = REPO + '/objects/pack'
GIT = %W[git --git-dir=#{REPO}].freeze
2019-12-26 22:10:19 +05:30
BASE_PACK = 'pack-691247af2a6acb0b63b73ac0cb90540e93614043'
2017-09-10 17:25:29 +05:30
def main
unpack
# We want to store the refs in a packed-refs file because if we don't
# they can get mangled by filesystems.
abort unless system(*GIT, *%w[pack-refs --all])
abort unless system(*GIT, 'fsck')
end
# We don't want contributors to commit new pack files because those
# create unnecessary churn.
def unpack
pack_files = Dir[File.join(PACK_DIR, '*')].reject do |pack|
pack.start_with?(File.join(PACK_DIR, BASE_PACK))
end
return if pack_files.empty?
pack_files.each do |pack|
unless pack.end_with?('.pack')
FileUtils.rm(pack)
next
end
File.open(pack, 'rb') do |open_pack|
File.unlink(pack)
abort unless system(*GIT, 'unpack-objects', in: open_pack)
end
end
end
main