summaryrefslogtreecommitdiff
path: root/t/t0093-verify-cache-df-gap.sh
blob: 0b6829d805269d991b1f4a139e0e5cfffebaeb93 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

test_description='verify_cache() must catch non-adjacent D/F conflicts

Ensure that verify_cache() can complain about bad entries like:

  docs               <-- submodule
  docs-internal/...  <-- sorts here because "-" < "/"
  docs/...           <-- D/F conflict with "docs" above, not adjacent

In order to test verify_cache, we directly construct a corrupt index
(bypassing the D/F safety checks in add_index_entry) and verify that
write-tree rejects it.
'

. ./test-lib.sh

if ! test_have_prereq PERL
then
	skip_all='skipping verify_cache D/F tests; Perl not available'
	test_done
fi

# Build a v2 index from entries on stdin, bypassing D/F checks.
# Each line: "octalmode hex-oid name" (entries must be pre-sorted).
build_corrupt_index () {
	perl "$TEST_DIRECTORY/t0093-direct-index-write.pl" >"$1"
}

test_expect_success 'setup objects' '
	test_commit base &&
	BLOB=$(git rev-parse HEAD:base.t) &&
	SUB_COMMIT=$(git rev-parse HEAD)
'

test_expect_success 'adjacent D/F conflict is caught by verify_cache' '
	cat >index-entries <<-EOF &&
	0160000 $SUB_COMMIT docs
	0100644 $BLOB docs/requirements.txt
	EOF
	build_corrupt_index .git/index <index-entries &&

	test_must_fail git write-tree 2>err &&
	test_grep "You have both docs and docs/requirements.txt" err
'

test_expect_success 'non-adjacent D/F conflict is caught by verify_cache' '
	cat >index-entries <<-EOF &&
	0160000 $SUB_COMMIT docs
	0100644 $BLOB docs-internal/README.md
	0100644 $BLOB docs/requirements.txt
	EOF
	build_corrupt_index .git/index <index-entries &&

	test_must_fail git write-tree 2>err &&
	test_grep "You have both docs and docs/requirements.txt" err
'

test_done