| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rev-list should handle unexpected object types' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | if ! test_have_prereq PERL_TEST_HELPERS |
| 8 | then |
| 9 | skip_all='skipping rev-list unexpected objects tests; Perl not available' |
| 10 | test_done |
| 11 | fi |
| 12 | |
| 13 | test_expect_success 'setup well-formed objects' ' |
| 14 | blob="$(printf "foo" | git hash-object -w --stdin)" && |
| 15 | tree="$(printf "100644 blob $blob\tfoo" | git mktree)" && |
| 16 | commit="$(git commit-tree $tree -m "first commit")" && |
| 17 | git cat-file commit $commit >good-commit |
| 18 | ' |
| 19 | |
| 20 | test_expect_success 'setup unexpected non-blob entry' ' |
| 21 | printf "100644 foo\0$(echo $tree | hex2oct)" >broken-tree && |
| 22 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'TODO (should fail!): traverse unexpected non-blob entry (lone)' ' |
| 26 | sed "s/Z$//" >expect <<-EOF && |
| 27 | $broken_tree Z |
| 28 | $tree foo |
| 29 | EOF |
| 30 | git rev-list --objects $broken_tree >actual && |
| 31 | test_cmp expect actual |
| 32 | ' |
| 33 | |
| 34 | test_expect_success 'traverse unexpected non-blob entry (seen)' ' |
| 35 | test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 && |
| 36 | test_grep "is not a blob" output |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'setup unexpected non-tree entry' ' |
| 40 | printf "40000 foo\0$(echo $blob | hex2oct)" >broken-tree && |
| 41 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 42 | ' |
| 43 | |
| 44 | test_expect_success 'traverse unexpected non-tree entry (lone)' ' |
| 45 | test_must_fail git rev-list --objects $broken_tree |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'traverse unexpected non-tree entry (seen)' ' |
| 49 | test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 && |
| 50 | test_grep "is not a tree" output |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'setup unexpected non-commit parent' ' |
| 54 | sed "/^author/ { h; s/.*/parent $blob/; G; }" <good-commit \ |
| 55 | >broken-commit && |
| 56 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 57 | broken-commit)" |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'traverse unexpected non-commit parent (lone)' ' |
| 61 | test_must_fail git rev-list --objects $broken_commit >output 2>&1 && |
| 62 | test_grep "not a commit" output |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'traverse unexpected non-commit parent (seen)' ' |
| 66 | test_must_fail git rev-list --objects $blob $broken_commit \ |
| 67 | >output 2>&1 && |
| 68 | test_grep "not a commit" output |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'setup unexpected non-tree root' ' |
| 72 | sed -e "s/$tree/$blob/" <good-commit >broken-commit && |
| 73 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 74 | broken-commit)" |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'traverse unexpected non-tree root (lone)' ' |
| 78 | test_must_fail git rev-list --objects $broken_commit |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'traverse unexpected non-tree root (seen)' ' |
| 82 | test_must_fail git rev-list --objects $blob $broken_commit \ |
| 83 | >output 2>&1 && |
| 84 | test_grep "not a tree" output |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'setup unexpected non-commit tag' ' |
| 88 | git tag -a -m "tagged commit" tag $commit && |
| 89 | git cat-file tag tag >good-tag && |
| 90 | test_when_finished "git tag -d tag" && |
| 91 | sed -e "s/$commit/$blob/" <good-tag >broken-tag && |
| 92 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'traverse unexpected non-commit tag (lone)' ' |
| 96 | test_must_fail git rev-list --objects $tag |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'traverse unexpected non-commit tag (seen)' ' |
| 100 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
| 101 | test_grep "not a commit" output |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'setup unexpected non-tree tag' ' |
| 105 | git tag -a -m "tagged tree" tag $tree && |
| 106 | git cat-file tag tag >good-tag && |
| 107 | test_when_finished "git tag -d tag" && |
| 108 | sed -e "s/$tree/$blob/" <good-tag >broken-tag && |
| 109 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 110 | ' |
| 111 | |
| 112 | test_expect_success 'traverse unexpected non-tree tag (lone)' ' |
| 113 | test_must_fail git rev-list --objects $tag |
| 114 | ' |
| 115 | |
| 116 | test_expect_success 'traverse unexpected non-tree tag (seen)' ' |
| 117 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
| 118 | test_grep "not a tree" output |
| 119 | ' |
| 120 | |
| 121 | test_expect_success 'setup unexpected non-blob tag' ' |
| 122 | git tag -a -m "tagged blob" tag $blob && |
| 123 | git cat-file tag tag >good-tag && |
| 124 | test_when_finished "git tag -d tag" && |
| 125 | sed -e "s/$blob/$commit/" <good-tag >broken-tag && |
| 126 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 127 | ' |
| 128 | |
| 129 | test_expect_success 'traverse unexpected non-blob tag (lone)' ' |
| 130 | test_must_fail git rev-list --objects $tag |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'traverse unexpected non-blob tag (seen)' ' |
| 134 | test_must_fail git rev-list --objects $commit $tag >output 2>&1 && |
| 135 | test_grep "not a blob" output |
| 136 | ' |
| 137 | |
| 138 | test_done |