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