]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6102-rev-list-unexpected-objects.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t6102-rev-list-unexpected-objects.sh
CommitLineData
0616617c
TB
1#!/bin/sh
2
3test_description='git rev-list should handle unexpected object types'
4
dd9cede9 5TEST_PASSES_SANITIZE_LEAK=true
0616617c
TB
6. ./test-lib.sh
7
8test_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
15test_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 20test_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
29test_expect_success 'traverse unexpected non-blob entry (seen)' '
30 test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 &&
6789275d 31 test_grep "is not a blob" output
0616617c
TB
32'
33
34test_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 39test_expect_success 'traverse unexpected non-tree entry (lone)' '
0616617c
TB
40 test_must_fail git rev-list --objects $broken_tree
41'
42
b49e74ea
TB
43test_expect_success 'traverse unexpected non-tree entry (seen)' '
44 test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 &&
6789275d 45 test_grep "is not a tree" output
0616617c
TB
46'
47
48test_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
55test_expect_success 'traverse unexpected non-commit parent (lone)' '
56 test_must_fail git rev-list --objects $broken_commit >output 2>&1 &&
6789275d 57 test_grep "not a commit" output
0616617c
TB
58'
59
60test_expect_success 'traverse unexpected non-commit parent (seen)' '
c78fe004 61 test_must_fail git rev-list --objects $blob $broken_commit \
0616617c 62 >output 2>&1 &&
6789275d 63 test_grep "not a commit" output
0616617c
TB
64'
65
66test_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 72test_expect_success 'traverse unexpected non-tree root (lone)' '
0616617c
TB
73 test_must_fail git rev-list --objects $broken_commit
74'
75
97dd512a
JK
76test_expect_success 'traverse unexpected non-tree root (seen)' '
77 test_must_fail git rev-list --objects $blob $broken_commit \
78 >output 2>&1 &&
6789275d 79 test_grep "not a tree" output
0616617c
TB
80'
81
82test_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
90test_expect_success 'traverse unexpected non-commit tag (lone)' '
91 test_must_fail git rev-list --objects $tag
92'
93
94test_expect_success 'traverse unexpected non-commit tag (seen)' '
95 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
6789275d 96 test_grep "not a commit" output
0616617c
TB
97'
98
99test_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
107test_expect_success 'traverse unexpected non-tree tag (lone)' '
108 test_must_fail git rev-list --objects $tag
109'
110
111test_expect_success 'traverse unexpected non-tree tag (seen)' '
112 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
6789275d 113 test_grep "not a tree" output
0616617c
TB
114'
115
116test_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
8db2dad7
JK
124test_expect_success 'traverse unexpected non-blob tag (lone)' '
125 test_must_fail git rev-list --objects $tag
0616617c
TB
126'
127
128test_expect_success 'traverse unexpected non-blob tag (seen)' '
129 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
6789275d 130 test_grep "not a blob" output
0616617c
TB
131'
132
133test_done