| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='verify_cache() must catch non-adjacent D/F conflicts |
| 4 | |
| 5 | Ensure 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 | |
| 11 | In 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 |
| 13 | write-tree rejects it. |
| 14 | ' |
| 15 | |
| 16 | . ./test-lib.sh |
| 17 | |
| 18 | if ! test_have_prereq PERL |
| 19 | then |
| 20 | skip_all='skipping verify_cache D/F tests; Perl not available' |
| 21 | test_done |
| 22 | fi |
| 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). |
| 26 | build_corrupt_index () { |
| 27 | perl "$TEST_DIRECTORY/t0093-direct-index-write.pl" >"$1" |
| 28 | } |
| 29 | |
| 30 | test_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 | |
| 36 | test_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 | |
| 47 | test_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 | |
| 59 | test_done |