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