Git fork
at reftables-rust 138 lines 4.4 kB view raw
1#!/bin/sh 2 3test_description='git rev-list should handle unexpected object types' 4 5. ./test-lib.sh 6 7if ! test_have_prereq PERL_TEST_HELPERS 8then 9 skip_all='skipping rev-list unexpected objects tests; Perl not available' 10 test_done 11fi 12 13test_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 20test_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 25test_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 34test_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 39test_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 44test_expect_success 'traverse unexpected non-tree entry (lone)' ' 45 test_must_fail git rev-list --objects $broken_tree 46' 47 48test_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 53test_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 60test_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 65test_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 71test_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 77test_expect_success 'traverse unexpected non-tree root (lone)' ' 78 test_must_fail git rev-list --objects $broken_commit 79' 80 81test_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 87test_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 95test_expect_success 'traverse unexpected non-commit tag (lone)' ' 96 test_must_fail git rev-list --objects $tag 97' 98 99test_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 104test_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 112test_expect_success 'traverse unexpected non-tree tag (lone)' ' 113 test_must_fail git rev-list --objects $tag 114' 115 116test_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 121test_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 129test_expect_success 'traverse unexpected non-blob tag (lone)' ' 130 test_must_fail git rev-list --objects $tag 131' 132 133test_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 138test_done