]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5701-git-serve.sh
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / t / t5701-git-serve.sh
CommitLineData
ed10cb95
BW
1#!/bin/sh
2
b7ce24d0 3test_description='test protocol v2 server commands'
ed10cb95 4
95cf2c01 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
ed10cb95
BW
8. ./test-lib.sh
9
10test_expect_success 'test capability advertisement' '
9de0dd36 11 test_oid_cache <<-EOF &&
12 wrong_algo sha1:sha256
13 wrong_algo sha256:sha1
14 EOF
ed10cb95
BW
15 cat >expect <<-EOF &&
16 version 2
17 agent=git/$(git version | cut -d" " -f3)
59e1205d 18 ls-refs=unborn
685fbd32 19 fetch=shallow
ecc3e534 20 server-option
9de0dd36 21 object-format=$(test_oid algo)
ed10cb95
BW
22 0000
23 EOF
24
b7ce24d0
JS
25 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
26 --advertise-capabilities >out &&
8ea40cc5 27 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 28 test_cmp expect actual
ed10cb95
BW
29'
30
31test_expect_success 'stateless-rpc flag does not list capabilities' '
32 # Empty request
8ea40cc5 33 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
34 0000
35 EOF
b7ce24d0 36 test-tool serve-v2 --stateless-rpc >out <in &&
ed10cb95
BW
37 test_must_be_empty out &&
38
39 # EOF
b7ce24d0 40 test-tool serve-v2 --stateless-rpc >out &&
ed10cb95
BW
41 test_must_be_empty out
42'
43
44test_expect_success 'request invalid capability' '
8ea40cc5 45 test-tool pkt-line pack >in <<-EOF &&
ed10cb95
BW
46 foobar
47 0000
48 EOF
b7ce24d0 49 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
50 test_i18ngrep "unknown capability" err
51'
52
53test_expect_success 'request with no command' '
8ea40cc5 54 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 55 agent=git/test
9de0dd36 56 object-format=$(test_oid algo)
ed10cb95
BW
57 0000
58 EOF
b7ce24d0 59 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
60 test_i18ngrep "no command requested" err
61'
62
63test_expect_success 'request invalid command' '
8ea40cc5 64 test-tool pkt-line pack >in <<-EOF &&
ed10cb95 65 command=foo
9de0dd36 66 object-format=$(test_oid algo)
ed10cb95
BW
67 agent=git/test
68 0000
69 EOF
b7ce24d0 70 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
ed10cb95
BW
71 test_i18ngrep "invalid command" err
72'
73
9de0dd36 74test_expect_success 'wrong object-format' '
75 test-tool pkt-line pack >in <<-EOF &&
76 command=fetch
77 agent=git/test
78 object-format=$(test_oid wrong_algo)
79 0000
80 EOF
81 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
82 test_i18ngrep "mismatched object format" err
83'
84
72d0ea00
BW
85# Test the basics of ls-refs
86#
87test_expect_success 'setup some refs and tags' '
88 test_commit one &&
95cf2c01 89 git branch dev main &&
72d0ea00 90 test_commit two &&
95cf2c01 91 git symbolic-ref refs/heads/release refs/heads/main &&
72d0ea00
BW
92 git tag -a -m "annotated tag" annotated-tag
93'
94
95test_expect_success 'basics of ls-refs' '
8ea40cc5 96 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 97 command=ls-refs
9de0dd36 98 object-format=$(test_oid algo)
72d0ea00
BW
99 0000
100 EOF
101
102 cat >expect <<-EOF &&
103 $(git rev-parse HEAD) HEAD
104 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 105 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
106 $(git rev-parse refs/heads/release) refs/heads/release
107 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
108 $(git rev-parse refs/tags/one) refs/tags/one
109 $(git rev-parse refs/tags/two) refs/tags/two
110 0000
111 EOF
112
b7ce24d0 113 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 114 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 115 test_cmp expect actual
72d0ea00
BW
116'
117
118test_expect_success 'basic ref-prefixes' '
8ea40cc5 119 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 120 command=ls-refs
9de0dd36 121 object-format=$(test_oid algo)
72d0ea00 122 0001
95cf2c01 123 ref-prefix refs/heads/main
72d0ea00
BW
124 ref-prefix refs/tags/one
125 0000
126 EOF
127
128 cat >expect <<-EOF &&
95cf2c01 129 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
130 $(git rev-parse refs/tags/one) refs/tags/one
131 0000
132 EOF
133
b7ce24d0 134 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 135 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 136 test_cmp expect actual
72d0ea00
BW
137'
138
139test_expect_success 'refs/heads prefix' '
8ea40cc5 140 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 141 command=ls-refs
9de0dd36 142 object-format=$(test_oid algo)
72d0ea00
BW
143 0001
144 ref-prefix refs/heads/
145 0000
146 EOF
147
148 cat >expect <<-EOF &&
149 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01 150 $(git rev-parse refs/heads/main) refs/heads/main
72d0ea00
BW
151 $(git rev-parse refs/heads/release) refs/heads/release
152 0000
153 EOF
154
b7ce24d0 155 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 156 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 157 test_cmp expect actual
72d0ea00
BW
158'
159
160test_expect_success 'peel parameter' '
8ea40cc5 161 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 162 command=ls-refs
9de0dd36 163 object-format=$(test_oid algo)
72d0ea00
BW
164 0001
165 peel
166 ref-prefix refs/tags/
167 0000
168 EOF
169
170 cat >expect <<-EOF &&
171 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
172 $(git rev-parse refs/tags/one) refs/tags/one
173 $(git rev-parse refs/tags/two) refs/tags/two
174 0000
175 EOF
176
b7ce24d0 177 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 178 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 179 test_cmp expect actual
72d0ea00
BW
180'
181
182test_expect_success 'symrefs parameter' '
8ea40cc5 183 test-tool pkt-line pack >in <<-EOF &&
72d0ea00 184 command=ls-refs
9de0dd36 185 object-format=$(test_oid algo)
72d0ea00
BW
186 0001
187 symrefs
188 ref-prefix refs/heads/
189 0000
190 EOF
191
192 cat >expect <<-EOF &&
193 $(git rev-parse refs/heads/dev) refs/heads/dev
95cf2c01
JS
194 $(git rev-parse refs/heads/main) refs/heads/main
195 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
72d0ea00
BW
196 0000
197 EOF
198
b7ce24d0 199 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 200 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 201 test_cmp expect actual
72d0ea00
BW
202'
203
ecc3e534 204test_expect_success 'sending server-options' '
8ea40cc5 205 test-tool pkt-line pack >in <<-EOF &&
ecc3e534 206 command=ls-refs
9de0dd36 207 object-format=$(test_oid algo)
ecc3e534
BW
208 server-option=hello
209 server-option=world
210 0001
211 ref-prefix HEAD
212 0000
213 EOF
214
215 cat >expect <<-EOF &&
216 $(git rev-parse HEAD) HEAD
217 0000
218 EOF
219
b7ce24d0 220 test-tool serve-v2 --stateless-rpc <in >out &&
8ea40cc5 221 test-tool pkt-line unpack <out >actual &&
dcbaa0b3 222 test_cmp expect actual
ecc3e534
BW
223'
224
7cc6ed2d
JT
225test_expect_success 'unexpected lines are not allowed in fetch request' '
226 git init server &&
227
8ea40cc5 228 test-tool pkt-line pack >in <<-EOF &&
7cc6ed2d 229 command=fetch
9de0dd36 230 object-format=$(test_oid algo)
7cc6ed2d
JT
231 0001
232 this-is-not-a-command
233 0000
234 EOF
235
b7ce24d0
JS
236 (
237 cd server &&
238 test_must_fail test-tool serve-v2 --stateless-rpc
239 ) <in >/dev/null 2>err &&
7cc6ed2d
JT
240 grep "unexpected line: .this-is-not-a-command." err
241'
242
ed10cb95 243test_done