15072ecce3360b43fc0ad414a881afc95cb2d40d
1#!/bin/sh
2
3test_description='git rev-list should handle unexpected object types'
4
5. ./test-lib.sh
6
7test_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
14test_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
19test_expect_failure 'traverse unexpected non-blob entry (lone)' '
20 test_must_fail git rev-list --objects $broken_tree
21'
22
23test_expect_failure 'traverse unexpected non-blob entry (seen)' '
24 test_must_fail git rev-list --objects $tree $broken_tree
25'
26
27test_expect_success 'setup unexpected non-tree entry' '
28 printf "40000 foo\0$(echo $blob | hex2oct)" >broken-tree &&
29 broken_tree="$(git hash-object -w --literally -t tree broken-tree)"
30'
31
32test_expect_failure 'traverse unexpected non-tree entry (lone)' '
33 test_must_fail git rev-list --objects $broken_tree
34'
35
36test_expect_failure 'traverse unexpected non-tree entry (seen)' '
37 test_must_fail git rev-list --objects $blob $broken_tree
38'
39
40test_expect_success 'setup unexpected non-commit parent' '
41 sed "/^author/ { h; s/.*/parent $blob/; G; }" <good-commit \
42 >broken-commit &&
43 broken_commit="$(git hash-object -w --literally -t commit \
44 broken-commit)"
45'
46
47test_expect_success 'traverse unexpected non-commit parent (lone)' '
48 test_must_fail git rev-list --objects $broken_commit >output 2>&1 &&
49 test_i18ngrep "not a commit" output
50'
51
52test_expect_success 'traverse unexpected non-commit parent (seen)' '
53 test_must_fail git rev-list --objects $commit $broken_commit \
54 >output 2>&1 &&
55 test_i18ngrep "not a commit" output
56'
57
58test_expect_success 'setup unexpected non-tree root' '
59 sed -e "s/$tree/$blob/" <good-commit >broken-commit &&
60 broken_commit="$(git hash-object -w --literally -t commit \
61 broken-commit)"
62'
63
64test_expect_failure 'traverse unexpected non-tree root (lone)' '
65 test_must_fail git rev-list --objects $broken_commit
66'
67
68test_expect_failure 'traverse unexpected non-tree root (seen)' '
69 test_must_fail git rev-list --objects $blob $broken_commit
70'
71
72test_expect_success 'setup unexpected non-commit tag' '
73 git tag -a -m "tagged commit" tag $commit &&
74 git cat-file tag tag >good-tag &&
75 test_when_finished "git tag -d tag" &&
76 sed -e "s/$commit/$blob/" <good-tag >broken-tag &&
77 tag=$(git hash-object -w --literally -t tag broken-tag)
78'
79
80test_expect_success 'traverse unexpected non-commit tag (lone)' '
81 test_must_fail git rev-list --objects $tag
82'
83
84test_expect_success 'traverse unexpected non-commit tag (seen)' '
85 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
86 test_i18ngrep "not a commit" output
87'
88
89test_expect_success 'setup unexpected non-tree tag' '
90 git tag -a -m "tagged tree" tag $tree &&
91 git cat-file tag tag >good-tag &&
92 test_when_finished "git tag -d tag" &&
93 sed -e "s/$tree/$blob/" <good-tag >broken-tag &&
94 tag=$(git hash-object -w --literally -t tag broken-tag)
95'
96
97test_expect_success 'traverse unexpected non-tree tag (lone)' '
98 test_must_fail git rev-list --objects $tag
99'
100
101test_expect_success 'traverse unexpected non-tree tag (seen)' '
102 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
103 test_i18ngrep "not a tree" output
104'
105
106test_expect_success 'setup unexpected non-blob tag' '
107 git tag -a -m "tagged blob" tag $blob &&
108 git cat-file tag tag >good-tag &&
109 test_when_finished "git tag -d tag" &&
110 sed -e "s/$blob/$commit/" <good-tag >broken-tag &&
111 tag=$(git hash-object -w --literally -t tag broken-tag)
112'
113
114test_expect_failure 'traverse unexpected non-blob tag (lone)' '
115 test_must_fail git rev-list --objects $tag
116'
117
118test_expect_success 'traverse unexpected non-blob tag (seen)' '
119 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
120 test_i18ngrep "not a blob" output
121'
122
123test_done