Use the final_oid_fn to finalize hashing of object IDs
[alt-git.git] / t / t5530-upload-pack-error.sh
blob7c1460eaa99865306ddfb5254584eba275e17a21
1 #!/bin/sh
3 test_description='errors in upload-pack'
5 . ./test-lib.sh
7 D=$(pwd)
9 corrupt_repo () {
10 object_sha1=$(git rev-parse "$1") &&
11 ob=$(expr "$object_sha1" : "\(..\)") &&
12 ject=$(expr "$object_sha1" : "..\(..*\)") &&
13 rm -f ".git/objects/$ob/$ject"
16 test_expect_success 'setup and corrupt repository' '
17 echo file >file &&
18 git add file &&
19 git rev-parse :file &&
20 git commit -a -m original &&
21 test_tick &&
22 echo changed >file &&
23 git commit -a -m changed &&
24 corrupt_repo HEAD:file
28 test_expect_success 'fsck fails' '
29 test_must_fail git fsck
32 test_expect_success 'upload-pack fails due to error in pack-objects packing' '
33 head=$(git rev-parse HEAD) &&
34 hexsz=$(test_oid hexsz) &&
35 printf "%04xwant %s\n00000009done\n0000" \
36 $(($hexsz + 10)) $head >input &&
37 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
38 test_i18ngrep "unable to read" output.err &&
39 test_i18ngrep "pack-objects died" output.err
42 test_expect_success 'corrupt repo differently' '
44 git hash-object -w file &&
45 corrupt_repo HEAD^^{tree}
49 test_expect_success 'fsck fails' '
50 test_must_fail git fsck
52 test_expect_success 'upload-pack fails due to error in rev-list' '
54 printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
55 $(($hexsz + 10)) $(git rev-parse HEAD) \
56 $(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
57 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
58 grep "bad tree object" output.err
61 test_expect_success 'upload-pack fails due to bad want (no object)' '
63 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
64 $(($hexsz + 29)) $(test_oid deadbeef) >input &&
65 test_must_fail git upload-pack . <input >output 2>output.err &&
66 grep "not our ref" output.err &&
67 grep "ERR" output &&
68 ! grep multi_ack_detailed output.err
71 test_expect_success 'upload-pack fails due to bad want (not tip)' '
73 oid=$(echo an object we have | git hash-object -w --stdin) &&
74 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
75 $(($hexsz + 29)) "$oid" >input &&
76 test_must_fail git upload-pack . <input >output 2>output.err &&
77 grep "not our ref" output.err &&
78 grep "ERR" output &&
79 ! grep multi_ack_detailed output.err
82 test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
84 printf "%04xwant %s\n00000009done\n0000" \
85 $((hexsz + 10)) $(git rev-parse HEAD) >input &&
86 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
87 grep "bad tree object" output.err &&
88 grep "pack-objects died" output.err
91 test_expect_success 'upload-pack tolerates EOF just after stateless client wants' '
92 test_commit initial &&
93 head=$(git rev-parse HEAD) &&
96 packetize "want $head" &&
97 packetize "shallow $head" &&
98 packetize "deepen 1" &&
99 printf "0000"
100 } >request &&
102 printf "0000" >expect &&
104 git upload-pack --stateless-rpc . <request >actual &&
105 test_cmp expect actual
108 test_expect_success 'create empty repository' '
110 mkdir foo &&
111 cd foo &&
112 git init
116 test_expect_success 'fetch fails' '
118 test_must_fail git fetch .. main
122 test_done