interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5308-pack-detect-duplicates.sh

82 lines · 2303 bytes Raw Blame History
1#!/bin/sh
2
3test_description='handling of duplicate objects in incoming packfiles'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-pack.sh
7
8test_expect_success 'setup' '
9 test_oid_cache <<-EOF
10 lo_oid sha1:e68fe8129b546b101aee9510c5328e7f21ca1d18
11 lo_oid sha256:471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe
12
13 missing_oid sha1:e69d000000000000000000000000000000000000
14 missing_oid sha256:4720000000000000000000000000000000000000000000000000000000000000
15 EOF
16'
17
18# The sha1s we have in our pack. It's important that these have the same
19# starting byte, so that they end up in the same fanout section of the index.
20# That lets us make sure we are exercising the binary search with both sets.
21LO_SHA1=$(test_oid lo_oid)
22HI_SHA1=$EMPTY_BLOB
23
24# And here's a "missing sha1" which will produce failed lookups. It must also
25# be in the same fanout section, and should be between the two (so that during
26# our binary search, we are sure to end up looking at one or the other of the
27# duplicate runs).
28MISSING_SHA1=$(test_oid missing_oid)
29
30# git will never intentionally create packfiles with
31# duplicate objects, so we have to construct them by hand.
32#
33# $1 is the name of the packfile to create
34#
35# $2 is the number of times to duplicate each object
36create_pack () {
37 pack_header "$((2 * $2))" >"$1" &&
38 for i in $(test_seq 1 "$2"); do
39 pack_obj $LO_SHA1 &&
40 pack_obj $HI_SHA1
41 done >>"$1" &&
42 pack_trailer "$1"
43}
44
45# double-check that create_pack actually works
46test_expect_success 'pack with no duplicates' '
47 create_pack no-dups.pack 1 &&
48 git index-pack --stdin <no-dups.pack
49'
50
51test_expect_success 'index-pack will allow duplicate objects by default' '
52 clear_packs &&
53 create_pack dups.pack 100 &&
54 git index-pack --stdin <dups.pack
55'
56
57test_expect_success 'create batch-check test vectors' '
58 cat >input <<-EOF &&
59 $LO_SHA1
60 $HI_SHA1
61 $MISSING_SHA1
62 EOF
63 cat >expect <<-EOF
64 $LO_SHA1 blob 2
65 $HI_SHA1 blob 0
66 $MISSING_SHA1 missing
67 EOF
68'
69
70test_expect_success 'lookup in duplicated pack' '
71 git cat-file --batch-check <input >actual &&
72 test_cmp expect actual
73'
74
75test_expect_success 'index-pack can reject packs with duplicates' '
76 clear_packs &&
77 create_pack dups.pack 2 &&
78 test_must_fail git index-pack --strict --stdin <dups.pack &&
79 test_expect_code 1 git cat-file -e $LO_SHA1
80'
81
82test_done