blob: d40292cfb7b48f79e1aac6a635b9f10de96745c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#!/bin/sh
test_description='errors in upload-pack'
. ./test-lib.sh
corrupt_repo () {
object_sha1=$(git rev-parse "$1") &&
ob=$(expr "$object_sha1" : "\(..\)") &&
ject=$(expr "$object_sha1" : "..\(..*\)") &&
rm -f ".git/objects/$ob/$ject"
}
test_expect_success 'setup and corrupt repository' '
echo file >file &&
git add file &&
git rev-parse :file &&
git commit -a -m original &&
test_tick &&
echo changed >file &&
git commit -a -m changed &&
corrupt_repo HEAD:file &&
test_must_fail git fsck
'
test_expect_success 'upload-pack fails due to error in pack-objects packing' '
head=$(git rev-parse HEAD) &&
hexsz=$(test_oid hexsz) &&
printf "%04xwant %s\n00000009done\n0000" \
$(($hexsz + 10)) $head >input &&
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
test_grep "unable to read" output.err &&
test_grep "pack-objects died" output.err
'
test_expect_success 'corrupt repo differently' '
git hash-object -w file &&
corrupt_repo HEAD^^{tree} &&
test_must_fail git fsck
'
test_expect_success 'upload-pack fails due to error in rev-list' '
printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
$(($hexsz + 10)) $(git rev-parse HEAD) \
$(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
grep "bad tree object" output.err
'
test_expect_success 'upload-pack fails due to bad want (no object)' '
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) $(test_oid deadbeef) >input &&
test_must_fail git upload-pack . <input >output 2>output.err &&
grep "not our ref" output.err &&
grep "ERR" output &&
! grep multi_ack_detailed output.err
'
test_expect_success 'upload-pack fails due to bad want (not tip)' '
oid=$(echo an object we have | git hash-object -w --stdin) &&
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) "$oid" >input &&
test_must_fail git upload-pack . <input >output 2>output.err &&
grep "not our ref" output.err &&
grep "ERR" output &&
! grep multi_ack_detailed output.err
'
test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
printf "%04xwant %s\n00000009done\n0000" \
$((hexsz + 10)) $(git rev-parse HEAD) >input &&
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
grep "bad tree object" output.err &&
grep "pack-objects died" output.err
'
test_expect_success 'upload-pack tolerates EOF just after stateless client wants' '
test_commit initial &&
head=$(git rev-parse HEAD) &&
{
packetize "want $head" &&
packetize "shallow $head" &&
packetize "deepen 1" &&
printf "0000"
} >request &&
printf "0000" >expect &&
git upload-pack --stateless-rpc . <request >actual &&
test_cmp expect actual
'
test_expect_success 'fetch fails' '
git init foo &&
test_must_fail git -C foo fetch .. main
'
test_expect_success 'upload-pack ACKs repeated non-commit objects repeatedly (protocol v0)' '
commit_id=$(git rev-parse HEAD) &&
tree_id=$(git rev-parse HEAD^{tree}) &&
test-tool pkt-line pack >request <<-EOF &&
want $commit_id
0000
have $tree_id
have $tree_id
0000
EOF
git upload-pack --stateless-rpc . <request >actual &&
depacketize <actual >actual.raw &&
grep ^ACK actual.raw >actual.acks &&
cat >expect <<-EOF &&
ACK $tree_id
ACK $tree_id
EOF
test_cmp expect actual.acks
'
test_expect_success 'upload-pack ACKs repeated non-commit objects once only (protocol v2)' '
commit_id=$(git rev-parse HEAD) &&
tree_id=$(git rev-parse HEAD^{tree}) &&
test-tool pkt-line pack >request <<-EOF &&
command=fetch
object-format=$(test_oid algo)
0001
want $commit_id
have $tree_id
have $tree_id
0000
EOF
GIT_PROTOCOL=version=2 git upload-pack . <request >actual &&
depacketize <actual >actual.raw &&
grep ^ACK actual.raw >actual.acks &&
echo "ACK $tree_id" >expect &&
test_cmp expect actual.acks
'
test_done
|