1#!/bin/sh
2
3test_description='errors in upload-pack'
4
5. ./test-lib.sh
6
7D=$(pwd)
8
9corrupt_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"
14}
15
16test_expect_success 'setup and corrupt repository' '
17
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
29test_expect_success 'fsck fails' '
30 test_must_fail git fsck
31'
32
33test_expect_success 'upload-pack fails due to error in pack-objects packing' '
34
35 printf "0032want %s\n00000009done\n0000" \
36 $(git rev-parse 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
40'
41
42test_expect_success 'corrupt repo differently' '
43
44 git hash-object -w file &&
45 corrupt_repo HEAD^^{tree}
46
47'
48
49test_expect_success 'fsck fails' '
50 test_must_fail git fsck
51'
52test_expect_success 'upload-pack fails due to error in rev-list' '
53
54 printf "0032want %s\n0034shallow %s00000009done\n0000" \
55 $(git rev-parse HEAD) $(git rev-parse HEAD^) >input &&
56 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
57 grep "bad tree object" output.err
58'
59
60test_expect_success 'upload-pack fails due to bad want (no object)' '
61
62 printf "0045want %s multi_ack_detailed\n00000009done\n0000" \
63 "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" >input &&
64 test_must_fail git upload-pack . <input >output 2>output.err &&
65 grep "not our ref" output.err &&
66 grep "ERR" output &&
67 ! grep multi_ack_detailed output.err
68'
69
70test_expect_success 'upload-pack fails due to bad want (not tip)' '
71
72 oid=$(echo an object we have | git hash-object -w --stdin) &&
73 printf "0045want %s multi_ack_detailed\n00000009done\n0000" \
74 "$oid" >input &&
75 test_must_fail git upload-pack . <input >output 2>output.err &&
76 grep "not our ref" output.err &&
77 grep "ERR" output &&
78 ! grep multi_ack_detailed output.err
79'
80
81test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
82
83 printf "0032want %s\n00000009done\n0000" \
84 $(git rev-parse HEAD) >input &&
85 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
86 grep "bad tree object" output.err &&
87 grep "pack-objects died" output.err
88'
89
90test_expect_success 'create empty repository' '
91
92 mkdir foo &&
93 cd foo &&
94 git init
95
96'
97
98test_expect_success 'fetch fails' '
99
100 test_must_fail git fetch .. master
101
102'
103
104test_done