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_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
26'
27
28test_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
33test_expect_failure 'traverse unexpected non-tree entry (lone)' '
34 test_must_fail git rev-list --objects $broken_tree
35'
36
37test_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
40'
41
42test_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
49test_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
54test_expect_success 'traverse unexpected non-commit parent (seen)' '
55 test_must_fail git rev-list --objects $commit $broken_commit \
56 >output 2>&1 &&
57 test_i18ngrep "not a commit" output
58'
59
60test_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
66test_expect_failure 'traverse unexpected non-tree root (lone)' '
67 test_must_fail git rev-list --objects $broken_commit
68'
69
70test_expect_failure 'traverse unexpected non-tree root (seen)' '
71 test_must_fail git rev-list --objects $blob $broken_commit
72'
73
74test_expect_success 'setup unexpected non-commit tag' '
75 git tag -a -m "tagged commit" tag $commit &&
76 git cat-file tag tag >good-tag &&
77 test_when_finished "git tag -d tag" &&
78 sed -e "s/$commit/$blob/" <good-tag >broken-tag &&
79 tag=$(git hash-object -w --literally -t tag broken-tag)
80'
81
82test_expect_success 'traverse unexpected non-commit tag (lone)' '
83 test_must_fail git rev-list --objects $tag
84'
85
86test_expect_success 'traverse unexpected non-commit tag (seen)' '
87 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
88 test_i18ngrep "not a commit" output
89'
90
91test_expect_success 'setup unexpected non-tree tag' '
92 git tag -a -m "tagged tree" tag $tree &&
93 git cat-file tag tag >good-tag &&
94 test_when_finished "git tag -d tag" &&
95 sed -e "s/$tree/$blob/" <good-tag >broken-tag &&
96 tag=$(git hash-object -w --literally -t tag broken-tag)
97'
98
99test_expect_success 'traverse unexpected non-tree tag (lone)' '
100 test_must_fail git rev-list --objects $tag
101'
102
103test_expect_success 'traverse unexpected non-tree tag (seen)' '
104 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
105 test_i18ngrep "not a tree" output
106'
107
108test_expect_success 'setup unexpected non-blob tag' '
109 git tag -a -m "tagged blob" tag $blob &&
110 git cat-file tag tag >good-tag &&
111 test_when_finished "git tag -d tag" &&
112 sed -e "s/$blob/$commit/" <good-tag >broken-tag &&
113 tag=$(git hash-object -w --literally -t tag broken-tag)
114'
115
116test_expect_failure 'traverse unexpected non-blob tag (lone)' '
117 test_must_fail git rev-list --objects $tag
118'
119
120test_expect_success 'traverse unexpected non-blob tag (seen)' '
121 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
122 test_i18ngrep "not a blob" output
123'
124
125test_done