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 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup well-formed objects' ' |
| 8 | blob="$(printf "foo" | git hash-object -w --stdin)" && |
| 9 | tree="$(printf "100644 blob $blob\tfoo" | git mktree)" && |
| 10 | commit="$(git commit-tree $tree -m "first commit")" && |
| 11 | git cat-file commit $commit >good-commit |
| 12 | ' |
| 13 | |
| 14 | test_expect_success 'setup unexpected non-blob entry' ' |
| 15 | printf "100644 foo\0$(echo $tree | hex2oct)" >broken-tree && |
| 16 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 17 | ' |
| 18 | |
| 19 | test_expect_failure 'traverse unexpected non-blob entry (lone)' ' |
| 20 | test_must_fail git rev-list --objects $broken_tree |
| 21 | ' |
| 22 | |
Taylor Blau | 23c2044 | 2019-04-09 19:13:17 -0700 | [diff] [blame] | 23 | test_expect_success 'traverse unexpected non-blob entry (seen)' ' |
| 24 | test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 && |
| 25 | test_i18ngrep "is not a blob" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 26 | ' |
| 27 | |
| 28 | test_expect_success 'setup unexpected non-tree entry' ' |
| 29 | printf "40000 foo\0$(echo $blob | hex2oct)" >broken-tree && |
| 30 | broken_tree="$(git hash-object -w --literally -t tree broken-tree)" |
| 31 | ' |
| 32 | |
Jeff King | ee4dfee | 2019-04-09 19:13:23 -0700 | [diff] [blame] | 33 | test_expect_success 'traverse unexpected non-tree entry (lone)' ' |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 34 | test_must_fail git rev-list --objects $broken_tree |
| 35 | ' |
| 36 | |
Taylor Blau | b49e74e | 2019-04-09 19:13:19 -0700 | [diff] [blame] | 37 | test_expect_success 'traverse unexpected non-tree entry (seen)' ' |
| 38 | test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 && |
| 39 | test_i18ngrep "is not a tree" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 40 | ' |
| 41 | |
| 42 | test_expect_success 'setup unexpected non-commit parent' ' |
| 43 | sed "/^author/ { h; s/.*/parent $blob/; G; }" <good-commit \ |
| 44 | >broken-commit && |
| 45 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 46 | broken-commit)" |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'traverse unexpected non-commit parent (lone)' ' |
| 50 | test_must_fail git rev-list --objects $broken_commit >output 2>&1 && |
| 51 | test_i18ngrep "not a commit" output |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'traverse unexpected non-commit parent (seen)' ' |
Jeff King | c78fe00 | 2019-10-18 00:42:13 -0400 | [diff] [blame] | 55 | test_must_fail git rev-list --objects $blob $broken_commit \ |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 56 | >output 2>&1 && |
| 57 | test_i18ngrep "not a commit" output |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'setup unexpected non-tree root' ' |
| 61 | sed -e "s/$tree/$blob/" <good-commit >broken-commit && |
| 62 | broken_commit="$(git hash-object -w --literally -t commit \ |
| 63 | broken-commit)" |
| 64 | ' |
| 65 | |
Jeff King | ee4dfee | 2019-04-09 19:13:23 -0700 | [diff] [blame] | 66 | test_expect_success 'traverse unexpected non-tree root (lone)' ' |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 67 | test_must_fail git rev-list --objects $broken_commit |
| 68 | ' |
| 69 | |
Jeff King | 97dd512 | 2019-04-09 19:13:25 -0700 | [diff] [blame] | 70 | test_expect_success 'traverse unexpected non-tree root (seen)' ' |
| 71 | test_must_fail git rev-list --objects $blob $broken_commit \ |
| 72 | >output 2>&1 && |
| 73 | test_i18ngrep "not a tree" output |
Taylor Blau | 0616617 | 2019-04-09 19:13:14 -0700 | [diff] [blame] | 74 | ' |
| 75 | |
| 76 | test_expect_success 'setup unexpected non-commit tag' ' |
| 77 | git tag -a -m "tagged commit" tag $commit && |
| 78 | git cat-file tag tag >good-tag && |
| 79 | test_when_finished "git tag -d tag" && |
| 80 | sed -e "s/$commit/$blob/" <good-tag >broken-tag && |
| 81 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'traverse unexpected non-commit tag (lone)' ' |
| 85 | test_must_fail git rev-list --objects $tag |
| 86 | ' |
| 87 | |
| 88 | test_expect_success 'traverse unexpected non-commit tag (seen)' ' |
| 89 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
| 90 | test_i18ngrep "not a commit" output |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'setup unexpected non-tree tag' ' |
| 94 | git tag -a -m "tagged tree" tag $tree && |
| 95 | git cat-file tag tag >good-tag && |
| 96 | test_when_finished "git tag -d tag" && |
| 97 | sed -e "s/$tree/$blob/" <good-tag >broken-tag && |
| 98 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'traverse unexpected non-tree tag (lone)' ' |
| 102 | test_must_fail git rev-list --objects $tag |
| 103 | ' |
| 104 | |
| 105 | test_expect_success 'traverse unexpected non-tree tag (seen)' ' |
| 106 | test_must_fail git rev-list --objects $blob $tag >output 2>&1 && |
| 107 | test_i18ngrep "not a tree" output |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'setup unexpected non-blob tag' ' |
| 111 | git tag -a -m "tagged blob" tag $blob && |
| 112 | git cat-file tag tag >good-tag && |
| 113 | test_when_finished "git tag -d tag" && |
| 114 | sed -e "s/$blob/$commit/" <good-tag >broken-tag && |
| 115 | tag=$(git hash-object -w --literally -t tag broken-tag) |
| 116 | ' |
| 117 | |
| 118 | test_expect_failure 'traverse unexpected non-blob tag (lone)' ' |
| 119 | test_must_fail git rev-list --objects $tag |
| 120 | ' |
| 121 | |
| 122 | test_expect_success 'traverse unexpected non-blob tag (seen)' ' |
| 123 | test_must_fail git rev-list --objects $commit $tag >output 2>&1 && |
| 124 | test_i18ngrep "not a blob" output |
| 125 | ' |
| 126 | |
| 127 | test_done |