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