]>
Commit | Line | Data |
---|---|---|
4c324c00 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='errors in upload-pack' | |
4 | ||
568cc818 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
4c324c00 JS |
6 | . ./test-lib.sh |
7 | ||
14dc2d98 | 8 | D=$(pwd) |
4c324c00 JS |
9 | |
10 | corrupt_repo () { | |
11 | object_sha1=$(git rev-parse "$1") && | |
12 | ob=$(expr "$object_sha1" : "\(..\)") && | |
13 | ject=$(expr "$object_sha1" : "..\(..*\)") && | |
14 | rm -f ".git/objects/$ob/$ject" | |
15 | } | |
16 | ||
17 | test_expect_success 'setup and corrupt repository' ' | |
4c324c00 JS |
18 | echo file >file && |
19 | git add file && | |
20 | git rev-parse :file && | |
21 | git commit -a -m original && | |
22 | test_tick && | |
23 | echo changed >file && | |
24 | git commit -a -m changed && | |
25 | corrupt_repo HEAD:file | |
26 | ||
27 | ' | |
28 | ||
41ac414e | 29 | test_expect_success 'fsck fails' ' |
d492b31c | 30 | test_must_fail git fsck |
4c324c00 JS |
31 | ' |
32 | ||
f0cea83f | 33 | test_expect_success 'upload-pack fails due to error in pack-objects packing' ' |
83207221 | 34 | head=$(git rev-parse HEAD) && |
35 | hexsz=$(test_oid hexsz) && | |
36 | printf "%04xwant %s\n00000009done\n0000" \ | |
37 | $(($hexsz + 10)) $head >input && | |
1d8cd418 | 38 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
6789275d JH |
39 | test_grep "unable to read" output.err && |
40 | test_grep "pack-objects died" output.err | |
4c324c00 JS |
41 | ' |
42 | ||
43 | test_expect_success 'corrupt repo differently' ' | |
44 | ||
45 | git hash-object -w file && | |
46 | corrupt_repo HEAD^^{tree} | |
47 | ||
48 | ' | |
49 | ||
41ac414e | 50 | test_expect_success 'fsck fails' ' |
d492b31c | 51 | test_must_fail git fsck |
4c324c00 JS |
52 | ' |
53 | test_expect_success 'upload-pack fails due to error in rev-list' ' | |
54 | ||
83207221 | 55 | printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \ |
56 | $(($hexsz + 10)) $(git rev-parse HEAD) \ | |
57 | $(($hexsz + 12)) $(git rev-parse HEAD^) >input && | |
1d8cd418 | 58 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
0ac77ec3 | 59 | grep "bad tree object" output.err |
4c324c00 JS |
60 | ' |
61 | ||
014ade74 | 62 | test_expect_success 'upload-pack fails due to bad want (no object)' ' |
9f9aa761 | 63 | |
83207221 | 64 | printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ |
65 | $(($hexsz + 29)) $(test_oid deadbeef) >input && | |
9f9aa761 | 66 | test_must_fail git upload-pack . <input >output 2>output.err && |
6963a4e4 JK |
67 | grep "not our ref" output.err && |
68 | grep "ERR" output && | |
69 | ! grep multi_ack_detailed output.err | |
9f9aa761 EN |
70 | ' |
71 | ||
014ade74 JK |
72 | test_expect_success 'upload-pack fails due to bad want (not tip)' ' |
73 | ||
74 | oid=$(echo an object we have | git hash-object -w --stdin) && | |
83207221 | 75 | printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ |
76 | $(($hexsz + 29)) "$oid" >input && | |
014ade74 JK |
77 | test_must_fail git upload-pack . <input >output 2>output.err && |
78 | grep "not our ref" output.err && | |
79 | grep "ERR" output && | |
80 | ! grep multi_ack_detailed output.err | |
81 | ' | |
82 | ||
f0cea83f NE |
83 | test_expect_success 'upload-pack fails due to error in pack-objects enumeration' ' |
84 | ||
83207221 | 85 | printf "%04xwant %s\n00000009done\n0000" \ |
86 | $((hexsz + 10)) $(git rev-parse HEAD) >input && | |
1d8cd418 | 87 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
f0cea83f NE |
88 | grep "bad tree object" output.err && |
89 | grep "pack-objects died" output.err | |
90 | ' | |
91 | ||
fb3d1a08 DD |
92 | test_expect_success 'upload-pack tolerates EOF just after stateless client wants' ' |
93 | test_commit initial && | |
94 | head=$(git rev-parse HEAD) && | |
95 | ||
96 | { | |
97 | packetize "want $head" && | |
98 | packetize "shallow $head" && | |
99 | packetize "deepen 1" && | |
100 | printf "0000" | |
101 | } >request && | |
102 | ||
103 | printf "0000" >expect && | |
104 | ||
105 | git upload-pack --stateless-rpc . <request >actual && | |
106 | test_cmp expect actual | |
107 | ' | |
108 | ||
4c324c00 JS |
109 | test_expect_success 'create empty repository' ' |
110 | ||
111 | mkdir foo && | |
112 | cd foo && | |
113 | git init | |
114 | ||
115 | ' | |
116 | ||
41ac414e | 117 | test_expect_success 'fetch fails' ' |
4c324c00 | 118 | |
3ac8f630 | 119 | test_must_fail git fetch .. main |
4c324c00 JS |
120 | |
121 | ' | |
122 | ||
123 | test_done |