blob: 5d28507efc687b12af0de9762668ec87fd03a0fc [file] [log] [blame]
Taylor Blau06166172019-04-09 19:13:14 -07001#!/bin/sh
2
3test_description='git rev-list should handle unexpected object types'
4
Ævar Arnfjörð Bjarmasondd9cede2021-10-31 00:24:14 +02005TEST_PASSES_SANITIZE_LEAK=true
Taylor Blau06166172019-04-09 19:13:14 -07006. ./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
Ævar Arnfjörð Bjarmason96ecf692022-07-28 01:13:40 +020020test_expect_success 'TODO (should fail!): traverse unexpected non-blob entry (lone)' '
Ævar Arnfjörð Bjarmasoncf10c5b2022-03-07 13:49:02 +010021 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
Taylor Blau06166172019-04-09 19:13:14 -070027'
28
Taylor Blau23c20442019-04-09 19:13:17 -070029test_expect_success 'traverse unexpected non-blob entry (seen)' '
30 test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +090031 test_grep "is not a blob" output
Taylor Blau06166172019-04-09 19:13:14 -070032'
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
Jeff Kingee4dfee2019-04-09 19:13:23 -070039test_expect_success 'traverse unexpected non-tree entry (lone)' '
Taylor Blau06166172019-04-09 19:13:14 -070040 test_must_fail git rev-list --objects $broken_tree
41'
42
Taylor Blaub49e74e2019-04-09 19:13:19 -070043test_expect_success 'traverse unexpected non-tree entry (seen)' '
44 test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +090045 test_grep "is not a tree" output
Taylor Blau06166172019-04-09 19:13:14 -070046'
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 &&
Junio C Hamano67892752023-10-31 14:23:30 +090057 test_grep "not a commit" output
Taylor Blau06166172019-04-09 19:13:14 -070058'
59
60test_expect_success 'traverse unexpected non-commit parent (seen)' '
Jeff Kingc78fe002019-10-18 00:42:13 -040061 test_must_fail git rev-list --objects $blob $broken_commit \
Taylor Blau06166172019-04-09 19:13:14 -070062 >output 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +090063 test_grep "not a commit" output
Taylor Blau06166172019-04-09 19:13:14 -070064'
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
Jeff Kingee4dfee2019-04-09 19:13:23 -070072test_expect_success 'traverse unexpected non-tree root (lone)' '
Taylor Blau06166172019-04-09 19:13:14 -070073 test_must_fail git rev-list --objects $broken_commit
74'
75
Jeff King97dd5122019-04-09 19:13:25 -070076test_expect_success 'traverse unexpected non-tree root (seen)' '
77 test_must_fail git rev-list --objects $blob $broken_commit \
78 >output 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +090079 test_grep "not a tree" output
Taylor Blau06166172019-04-09 19:13:14 -070080'
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 &&
Junio C Hamano67892752023-10-31 14:23:30 +090096 test_grep "not a commit" output
Taylor Blau06166172019-04-09 19:13:14 -070097'
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 &&
Junio C Hamano67892752023-10-31 14:23:30 +0900113 test_grep "not a tree" output
Taylor Blau06166172019-04-09 19:13:14 -0700114'
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
Jeff King8db2dad2022-11-17 17:41:16 -0500124test_expect_success 'traverse unexpected non-blob tag (lone)' '
125 test_must_fail git rev-list --objects $tag
Taylor Blau06166172019-04-09 19:13:14 -0700126'
127
128test_expect_success 'traverse unexpected non-blob tag (seen)' '
129 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +0900130 test_grep "not a blob" output
Taylor Blau06166172019-04-09 19:13:14 -0700131'
132
133test_done