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_failure 'traverse unexpected non-tree entry (seen)' '
38 test_must_fail git rev-list --objects $blob $broken_tree
39'
40
41test_expect_success 'setup unexpected non-commit parent' '
42 sed "/^author/ { h; s/.*/parent $blob/; G; }" <good-commit \
43 >broken-commit &&
44 broken_commit="$(git hash-object -w --literally -t commit \
45 broken-commit)"
46'
47
48test_expect_success 'traverse unexpected non-commit parent (lone)' '
49 test_must_fail git rev-list --objects $broken_commit >output 2>&1 &&
50 test_i18ngrep "not a commit" output
51'
52
53test_expect_success 'traverse unexpected non-commit parent (seen)' '
54 test_must_fail git rev-list --objects $commit $broken_commit \
55 >output 2>&1 &&
56 test_i18ngrep "not a commit" output
57'
58
59test_expect_success 'setup unexpected non-tree root' '
60 sed -e "s/$tree/$blob/" <good-commit >broken-commit &&
61 broken_commit="$(git hash-object -w --literally -t commit \
62 broken-commit)"
63'
64
65test_expect_failure 'traverse unexpected non-tree root (lone)' '
66 test_must_fail git rev-list --objects $broken_commit
67'
68
69test_expect_failure 'traverse unexpected non-tree root (seen)' '
70 test_must_fail git rev-list --objects $blob $broken_commit
71'
72
73test_expect_success 'setup unexpected non-commit tag' '
74 git tag -a -m "tagged commit" tag $commit &&
75 git cat-file tag tag >good-tag &&
76 test_when_finished "git tag -d tag" &&
77 sed -e "s/$commit/$blob/" <good-tag >broken-tag &&
78 tag=$(git hash-object -w --literally -t tag broken-tag)
79'
80
81test_expect_success 'traverse unexpected non-commit tag (lone)' '
82 test_must_fail git rev-list --objects $tag
83'
84
85test_expect_success 'traverse unexpected non-commit tag (seen)' '
86 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
87 test_i18ngrep "not a commit" output
88'
89
90test_expect_success 'setup unexpected non-tree tag' '
91 git tag -a -m "tagged tree" tag $tree &&
92 git cat-file tag tag >good-tag &&
93 test_when_finished "git tag -d tag" &&
94 sed -e "s/$tree/$blob/" <good-tag >broken-tag &&
95 tag=$(git hash-object -w --literally -t tag broken-tag)
96'
97
98test_expect_success 'traverse unexpected non-tree tag (lone)' '
99 test_must_fail git rev-list --objects $tag
100'
101
102test_expect_success 'traverse unexpected non-tree tag (seen)' '
103 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
104 test_i18ngrep "not a tree" output
105'
106
107test_expect_success 'setup unexpected non-blob tag' '
108 git tag -a -m "tagged blob" tag $blob &&
109 git cat-file tag tag >good-tag &&
110 test_when_finished "git tag -d tag" &&
111 sed -e "s/$blob/$commit/" <good-tag >broken-tag &&
112 tag=$(git hash-object -w --literally -t tag broken-tag)
113'
114
115test_expect_failure 'traverse unexpected non-blob tag (lone)' '
116 test_must_fail git rev-list --objects $tag
117'
118
119test_expect_success 'traverse unexpected non-blob tag (seen)' '
120 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
121 test_i18ngrep "not a blob" output
122'
123
124test_done