]>
Commit | Line | Data |
---|---|---|
0616617c TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rev-list should handle unexpected object types' | |
4 | ||
dd9cede9 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
0616617c TB |
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 | ||
96ecf699 | 20 | test_expect_success 'TODO (should fail!): traverse unexpected non-blob entry (lone)' ' |
cf10c5b4 ÆAB |
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 | |
0616617c TB |
27 | ' |
28 | ||
23c20445 TB |
29 | test_expect_success 'traverse unexpected non-blob entry (seen)' ' |
30 | test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 && | |
31 | test_i18ngrep "is not a blob" output | |
0616617c TB |
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 | ||
ee4dfee2 | 39 | test_expect_success 'traverse unexpected non-tree entry (lone)' ' |
0616617c TB |
40 | test_must_fail git rev-list --objects $broken_tree |
41 | ' | |
42 | ||
b49e74ea TB |
43 | test_expect_success 'traverse unexpected non-tree entry (seen)' ' |
44 | test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 && | |
45 | test_i18ngrep "is not a tree" output | |
0616617c TB |
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 && | |
57 | test_i18ngrep "not a commit" output | |
58 | ' | |
59 | ||
60 | test_expect_success 'traverse unexpected non-commit parent (seen)' ' | |
c78fe004 | 61 | test_must_fail git rev-list --objects $blob $broken_commit \ |
0616617c TB |
62 | >output 2>&1 && |
63 | test_i18ngrep "not a commit" output | |
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 | ||
ee4dfee2 | 72 | test_expect_success 'traverse unexpected non-tree root (lone)' ' |
0616617c TB |
73 | test_must_fail git rev-list --objects $broken_commit |
74 | ' | |
75 | ||
97dd512a JK |
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 && | |
79 | test_i18ngrep "not a tree" output | |
0616617c TB |
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 && | |
96 | test_i18ngrep "not a commit" output | |
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 && | |
113 | test_i18ngrep "not a tree" output | |
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 | ||
96ecf699 | 124 | test_expect_success 'TODO (should fail!): traverse unexpected non-blob tag (lone)' ' |
cf10c5b4 | 125 | git rev-list --objects $tag |
0616617c TB |
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 && | |
130 | test_i18ngrep "not a blob" output | |
131 | ' | |
132 | ||
133 | test_done |