Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rev-list should handle unexpected object types' |
| 4 | |
Ævar Arnfjörð Bjarmason | dd9cede | 2021-10-31 00:24:14 +0200 | [diff] [blame] | 5 | TEST_PASSES_SANITIZE_LEAK=true |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
| 8 | test_expect_success 'setup well-formed objects' ' |
| 9 | blob="$(printf "foo" | git hash-object -w --stdin)" && |
| 10 | tree="$(printf "100644 blob $blob\tfoo" | git mktree)" && |
| 11 | commit="$(git commit-tree $tree -m "first commit")" && |
| 12 | git cat-file commit $commit >good-commit |
| 13 | ' |
| 14 | |
| 15 | test_expect_success 'setup unexpected non-blob entry' ' |
| 16 | printf "100644 foo\0$(echo $tree | hex2oct)" >broken-tree && |
| 17 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 18 | ' |
| 19 | |
Ævar Arnfjörð Bjarmason | 96ecf69 | 2022-07-28 01:13:40 +0200 | [diff] [blame] | 20 | test_expect_success 'TODO (should fail!): traverse unexpected non-blob entry (lone)' ' |
Ævar Arnfjörð Bjarmason | cf10c5b | 2022-03-07 13:49:02 +0100 | [diff] [blame] | 21 | sed "s/Z$//" >expect <<-EOF && |
| 22 | $broken_tree Z |
| 23 | $tree foo |
| 24 | EOF |
| 25 | git rev-list --objects $broken_tree >actual && |
| 26 | test_cmp expect actual |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 27 | ' |
| 28 | |
Taylor Blau | 23c2044 | 2019-04-09 19:13:17 -0700 | [diff] [blame] | 29 | test_expect_success 'traverse unexpected non-blob entry (seen)' ' |
| 30 | test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 31 | test_grep "is not a blob" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 32 | ' |
| 33 | |
| 34 | test_expect_success 'setup unexpected non-tree entry' ' |
| 35 | printf "40000 foo\0$(echo $blob | hex2oct)" >broken-tree && |
| 36 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 37 | ' |
| 38 | |
Jeff King | ee4dfee | 2019-04-09 19:13:23 -0700 | [diff] [blame] | 39 | test_expect_success 'traverse unexpected non-tree entry (lone)' ' |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 40 | test_must_fail git rev-list --objects $broken_tree |
| 41 | ' |
| 42 | |
Taylor Blau | b49e74e | 2019-04-09 19:13:19 -0700 | [diff] [blame] | 43 | test_expect_success 'traverse unexpected non-tree entry (seen)' ' |
| 44 | test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 45 | test_grep "is not a tree" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 46 | ' |
| 47 | |
| 48 | test_expect_success 'setup unexpected non-commit parent' ' |
| 49 | sed "/^author/ { h; s/.*/parent $blob/; G; }" <good-commit \ |
| 50 | >broken-commit && |
| 51 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 52 | broken-commit)" |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'traverse unexpected non-commit parent (lone)' ' |
| 56 | test_must_fail git rev-list --objects $broken_commit >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 57 | test_grep "not a commit" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 58 | ' |
| 59 | |
| 60 | test_expect_success 'traverse unexpected non-commit parent (seen)' ' |
Jeff King | c78fe00 | 2019-10-18 00:42:13 -0400 | [diff] [blame] | 61 | test_must_fail git rev-list --objects $blob $broken_commit \ |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 62 | >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 63 | test_grep "not a commit" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 64 | ' |
| 65 | |
| 66 | test_expect_success 'setup unexpected non-tree root' ' |
| 67 | sed -e "s/$tree/$blob/" <good-commit >broken-commit && |
| 68 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 69 | broken-commit)" |
| 70 | ' |
| 71 | |
Jeff King | ee4dfee | 2019-04-09 19:13:23 -0700 | [diff] [blame] | 72 | test_expect_success 'traverse unexpected non-tree root (lone)' ' |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 73 | test_must_fail git rev-list --objects $broken_commit |
| 74 | ' |
| 75 | |
Jeff King | 97dd512 | 2019-04-09 19:13:25 -0700 | [diff] [blame] | 76 | test_expect_success 'traverse unexpected non-tree root (seen)' ' |
| 77 | test_must_fail git rev-list --objects $blob $broken_commit \ |
| 78 | >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 79 | test_grep "not a tree" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 80 | ' |
| 81 | |
| 82 | test_expect_success 'setup unexpected non-commit tag' ' |
| 83 | git tag -a -m "tagged commit" tag $commit && |
| 84 | git cat-file tag tag >good-tag && |
| 85 | test_when_finished "git tag -d tag" && |
| 86 | sed -e "s/$commit/$blob/" <good-tag >broken-tag && |
| 87 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'traverse unexpected non-commit tag (lone)' ' |
| 91 | test_must_fail git rev-list --objects $tag |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'traverse unexpected non-commit tag (seen)' ' |
| 95 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 96 | test_grep "not a commit" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 97 | ' |
| 98 | |
| 99 | test_expect_success 'setup unexpected non-tree tag' ' |
| 100 | git tag -a -m "tagged tree" tag $tree && |
| 101 | git cat-file tag tag >good-tag && |
| 102 | test_when_finished "git tag -d tag" && |
| 103 | sed -e "s/$tree/$blob/" <good-tag >broken-tag && |
| 104 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'traverse unexpected non-tree tag (lone)' ' |
| 108 | test_must_fail git rev-list --objects $tag |
| 109 | ' |
| 110 | |
| 111 | test_expect_success 'traverse unexpected non-tree tag (seen)' ' |
| 112 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 113 | test_grep "not a tree" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 114 | ' |
| 115 | |
| 116 | test_expect_success 'setup unexpected non-blob tag' ' |
| 117 | git tag -a -m "tagged blob" tag $blob && |
| 118 | git cat-file tag tag >good-tag && |
| 119 | test_when_finished "git tag -d tag" && |
| 120 | sed -e "s/$blob/$commit/" <good-tag >broken-tag && |
| 121 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 122 | ' |
| 123 | |
Jeff King | 8db2dad | 2022-11-17 17:41:16 -0500 | [diff] [blame] | 124 | test_expect_success 'traverse unexpected non-blob tag (lone)' ' |
| 125 | test_must_fail git rev-list --objects $tag |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 126 | ' |
| 127 | |
| 128 | test_expect_success 'traverse unexpected non-blob tag (seen)' ' |
| 129 | test_must_fail git rev-list --objects $commit $tag >output 2>&1 && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 130 | test_grep "not a blob" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 131 | ' |
| 132 | |
| 133 | test_done |