File: unpack-gitlab-git-test

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (40 lines) | stat: -rwxr-xr-x 991 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fileutils'

REPO = 'spec/support/gitlab-git-test.git'
PACK_DIR = REPO + '/objects/pack'
GIT = %W[git --git-dir=#{REPO}].freeze
BASE_PACK = 'pack-691247af2a6acb0b63b73ac0cb90540e93614043'

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