var: avoid a segmentation fault when `HOME` is unset
[git.git] / t / t6102-rev-list-unexpected-objects.sh
blob9350b5fd2c235604560782e0412ed8f9fee069e3
1 #!/bin/sh
3 test_description='git rev-list should handle unexpected object types'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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
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)"
20 test_expect_success 'TODO (should fail!): traverse unexpected non-blob entry (lone)' '
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
29 test_expect_success 'traverse unexpected non-blob entry (seen)' '
30 test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 &&
31 test_i18ngrep "is not a blob" output
34 test_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)"
39 test_expect_success 'traverse unexpected non-tree entry (lone)' '
40 test_must_fail git rev-list --objects $broken_tree
43 test_expect_success 'traverse unexpected non-tree entry (seen)' '
44 test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 &&
45 test_i18ngrep "is not a tree" output
48 test_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)"
55 test_expect_success 'traverse unexpected non-commit parent (lone)' '
56 test_must_fail git rev-list --objects $broken_commit >output 2>&1 &&
57 test_i18ngrep "not a commit" output
60 test_expect_success 'traverse unexpected non-commit parent (seen)' '
61 test_must_fail git rev-list --objects $blob $broken_commit \
62 >output 2>&1 &&
63 test_i18ngrep "not a commit" output
66 test_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)"
72 test_expect_success 'traverse unexpected non-tree root (lone)' '
73 test_must_fail git rev-list --objects $broken_commit
76 test_expect_success 'traverse unexpected non-tree root (seen)' '
77 test_must_fail git rev-list --objects $blob $broken_commit \
78 >output 2>&1 &&
79 test_i18ngrep "not a tree" output
82 test_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)
90 test_expect_success 'traverse unexpected non-commit tag (lone)' '
91 test_must_fail git rev-list --objects $tag
94 test_expect_success 'traverse unexpected non-commit tag (seen)' '
95 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
96 test_i18ngrep "not a commit" output
99 test_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)
107 test_expect_success 'traverse unexpected non-tree tag (lone)' '
108 test_must_fail git rev-list --objects $tag
111 test_expect_success 'traverse unexpected non-tree tag (seen)' '
112 test_must_fail git rev-list --objects $blob $tag >output 2>&1 &&
113 test_i18ngrep "not a tree" output
116 test_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)
124 test_expect_success 'traverse unexpected non-blob tag (lone)' '
125 test_must_fail git rev-list --objects $tag
128 test_expect_success 'traverse unexpected non-blob tag (seen)' '
129 test_must_fail git rev-list --objects $commit $tag >output 2>&1 &&
130 test_i18ngrep "not a blob" output
133 test_done