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 / t0093-verify-cache-df-gap.sh

59 lines · 1657 bytes Raw Blame History
1#!/bin/sh
2
3test_description='verify_cache() must catch non-adjacent D/F conflicts
4
5Ensure that verify_cache() can complain about bad entries like:
6
7 docs <-- submodule
8 docs-internal/... <-- sorts here because "-" < "/"
9 docs/... <-- D/F conflict with "docs" above, not adjacent
10
11In order to test verify_cache, we directly construct a corrupt index
12(bypassing the D/F safety checks in add_index_entry) and verify that
13write-tree rejects it.
14'
15
16. ./test-lib.sh
17
18if ! test_have_prereq PERL
19then
20 skip_all='skipping verify_cache D/F tests; Perl not available'
21 test_done
22fi
23
24# Build a v2 index from entries on stdin, bypassing D/F checks.
25# Each line: "octalmode hex-oid name" (entries must be pre-sorted).
26build_corrupt_index () {
27 perl "$TEST_DIRECTORY/t0093-direct-index-write.pl" >"$1"
28}
29
30test_expect_success 'setup objects' '
31 test_commit base &&
32 BLOB=$(git rev-parse HEAD:base.t) &&
33 SUB_COMMIT=$(git rev-parse HEAD)
34'
35
36test_expect_success 'adjacent D/F conflict is caught by verify_cache' '
37 cat >index-entries <<-EOF &&
38 0160000 $SUB_COMMIT docs
39 0100644 $BLOB docs/requirements.txt
40 EOF
41 build_corrupt_index .git/index <index-entries &&
42
43 test_must_fail git write-tree 2>err &&
44 test_grep "You have both docs and docs/requirements.txt" err
45'
46
47test_expect_success 'non-adjacent D/F conflict is caught by verify_cache' '
48 cat >index-entries <<-EOF &&
49 0160000 $SUB_COMMIT docs
50 0100644 $BLOB docs-internal/README.md
51 0100644 $BLOB docs/requirements.txt
52 EOF
53 build_corrupt_index .git/index <index-entries &&
54
55 test_must_fail git write-tree 2>err &&
56 test_grep "You have both docs and docs/requirements.txt" err
57'
58
59test_done