completion: perform DWIM logic directly in __git_complete_refs
[alt-git.git] / t / t5530-upload-pack-error.sh
blob4ce9a9f7041112e49061acf14e0a51076ba770d2
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 test_oid_init &&
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
29 test_expect_success 'fsck fails' '
30 test_must_fail git fsck
33 test_expect_success 'upload-pack fails due to error in pack-objects packing' '
34 head=$(git rev-parse HEAD) &&
35 hexsz=$(test_oid hexsz) &&
36 printf "%04xwant %s\n00000009done\n0000" \
37 $(($hexsz + 10)) $head >input &&
38 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
39 test_i18ngrep "unable to read" output.err &&
40 test_i18ngrep "pack-objects died" output.err
43 test_expect_success 'corrupt repo differently' '
45 git hash-object -w file &&
46 corrupt_repo HEAD^^{tree}
50 test_expect_success 'fsck fails' '
51 test_must_fail git fsck
53 test_expect_success 'upload-pack fails due to error in rev-list' '
55 printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
56 $(($hexsz + 10)) $(git rev-parse HEAD) \
57 $(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
58 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
59 grep "bad tree object" output.err
62 test_expect_success 'upload-pack fails due to bad want (no object)' '
64 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
65 $(($hexsz + 29)) $(test_oid deadbeef) >input &&
66 test_must_fail git upload-pack . <input >output 2>output.err &&
67 grep "not our ref" output.err &&
68 grep "ERR" output &&
69 ! grep multi_ack_detailed output.err
72 test_expect_success 'upload-pack fails due to bad want (not tip)' '
74 oid=$(echo an object we have | git hash-object -w --stdin) &&
75 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
76 $(($hexsz + 29)) "$oid" >input &&
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
83 test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
85 printf "%04xwant %s\n00000009done\n0000" \
86 $((hexsz + 10)) $(git rev-parse HEAD) >input &&
87 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
88 grep "bad tree object" output.err &&
89 grep "pack-objects died" output.err
92 test_expect_success 'create empty repository' '
94 mkdir foo &&
95 cd foo &&
96 git init
100 test_expect_success 'fetch fails' '
102 test_must_fail git fetch .. master
106 test_done