read-tree: narrow scope of index expansion for '--prefix'
[alt-git.git] / t / t5701-git-serve.sh
blob1896f671cb37f916bc09e50f0f5a45df81da1327
1 #!/bin/sh
3 test_description='test protocol v2 server commands'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
15 EOF
16 cat >expect <<-EOF &&
17 version 2
18 agent=git/$(git version | cut -d" " -f3)
19 ls-refs=unborn
20 fetch=shallow wait-for-done
21 server-option
22 object-format=$(test_oid algo)
23 object-info
24 0000
25 EOF
27 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
28 --advertise-capabilities >out &&
29 test-tool pkt-line unpack <out >actual &&
30 test_cmp expect actual
33 test_expect_success 'stateless-rpc flag does not list capabilities' '
34 # Empty request
35 test-tool pkt-line pack >in <<-EOF &&
36 0000
37 EOF
38 test-tool serve-v2 --stateless-rpc >out <in &&
39 test_must_be_empty out &&
41 # EOF
42 test-tool serve-v2 --stateless-rpc >out &&
43 test_must_be_empty out
46 test_expect_success 'request invalid capability' '
47 test-tool pkt-line pack >in <<-EOF &&
48 foobar
49 0000
50 EOF
51 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
52 test_i18ngrep "unknown capability" err
55 test_expect_success 'request with no command' '
56 test-tool pkt-line pack >in <<-EOF &&
57 agent=git/test
58 object-format=$(test_oid algo)
59 0000
60 EOF
61 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
62 test_i18ngrep "no command requested" err
65 test_expect_success 'request invalid command' '
66 test-tool pkt-line pack >in <<-EOF &&
67 command=foo
68 object-format=$(test_oid algo)
69 agent=git/test
70 0000
71 EOF
72 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
73 test_i18ngrep "invalid command" err
76 test_expect_success 'request capability as command' '
77 test-tool pkt-line pack >in <<-EOF &&
78 command=agent
79 object-format=$(test_oid algo)
80 0000
81 EOF
82 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
83 grep invalid.command.*agent err
86 test_expect_success 'request command as capability' '
87 test-tool pkt-line pack >in <<-EOF &&
88 command=ls-refs
89 object-format=$(test_oid algo)
90 fetch
91 0000
92 EOF
93 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
94 grep unknown.capability err
97 test_expect_success 'requested command is command=value' '
98 test-tool pkt-line pack >in <<-EOF &&
99 command=ls-refs=whatever
100 object-format=$(test_oid algo)
101 0000
103 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
104 grep invalid.command.*ls-refs=whatever err
107 test_expect_success 'wrong object-format' '
108 test-tool pkt-line pack >in <<-EOF &&
109 command=fetch
110 agent=git/test
111 object-format=$(test_oid wrong_algo)
112 0000
114 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
115 test_i18ngrep "mismatched object format" err
118 # Test the basics of ls-refs
120 test_expect_success 'setup some refs and tags' '
121 test_commit one &&
122 git branch dev main &&
123 test_commit two &&
124 git symbolic-ref refs/heads/release refs/heads/main &&
125 git tag -a -m "annotated tag" annotated-tag
128 test_expect_success 'basics of ls-refs' '
129 test-tool pkt-line pack >in <<-EOF &&
130 command=ls-refs
131 object-format=$(test_oid algo)
132 0000
135 cat >expect <<-EOF &&
136 $(git rev-parse HEAD) HEAD
137 $(git rev-parse refs/heads/dev) refs/heads/dev
138 $(git rev-parse refs/heads/main) refs/heads/main
139 $(git rev-parse refs/heads/release) refs/heads/release
140 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
141 $(git rev-parse refs/tags/one) refs/tags/one
142 $(git rev-parse refs/tags/two) refs/tags/two
143 0000
146 test-tool serve-v2 --stateless-rpc <in >out &&
147 test-tool pkt-line unpack <out >actual &&
148 test_cmp expect actual
151 test_expect_success 'ls-refs complains about unknown options' '
152 test-tool pkt-line pack >in <<-EOF &&
153 command=ls-refs
154 object-format=$(test_oid algo)
155 0001
156 no-such-arg
157 0000
160 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
161 grep unexpected.line.*no-such-arg err
164 test_expect_success 'basic ref-prefixes' '
165 test-tool pkt-line pack >in <<-EOF &&
166 command=ls-refs
167 object-format=$(test_oid algo)
168 0001
169 ref-prefix refs/heads/main
170 ref-prefix refs/tags/one
171 0000
174 cat >expect <<-EOF &&
175 $(git rev-parse refs/heads/main) refs/heads/main
176 $(git rev-parse refs/tags/one) refs/tags/one
177 0000
180 test-tool serve-v2 --stateless-rpc <in >out &&
181 test-tool pkt-line unpack <out >actual &&
182 test_cmp expect actual
185 test_expect_success 'refs/heads prefix' '
186 test-tool pkt-line pack >in <<-EOF &&
187 command=ls-refs
188 object-format=$(test_oid algo)
189 0001
190 ref-prefix refs/heads/
191 0000
194 cat >expect <<-EOF &&
195 $(git rev-parse refs/heads/dev) refs/heads/dev
196 $(git rev-parse refs/heads/main) refs/heads/main
197 $(git rev-parse refs/heads/release) refs/heads/release
198 0000
201 test-tool serve-v2 --stateless-rpc <in >out &&
202 test-tool pkt-line unpack <out >actual &&
203 test_cmp expect actual
206 test_expect_success 'ignore very large set of prefixes' '
207 # generate a large number of ref-prefixes that we expect
208 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
209 # from ls-refs.c.
211 echo command=ls-refs &&
212 echo object-format=$(test_oid algo) &&
213 echo 0001 &&
214 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
215 echo 0000
217 test-tool pkt-line pack >in &&
219 # and then confirm that we see unmatched prefixes anyway (i.e.,
220 # that the prefix was not applied).
221 cat >expect <<-EOF &&
222 $(git rev-parse HEAD) HEAD
223 $(git rev-parse refs/heads/dev) refs/heads/dev
224 $(git rev-parse refs/heads/main) refs/heads/main
225 $(git rev-parse refs/heads/release) refs/heads/release
226 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
227 $(git rev-parse refs/tags/one) refs/tags/one
228 $(git rev-parse refs/tags/two) refs/tags/two
229 0000
232 test-tool serve-v2 --stateless-rpc <in >out &&
233 test-tool pkt-line unpack <out >actual &&
234 test_cmp expect actual
237 test_expect_success 'peel parameter' '
238 test-tool pkt-line pack >in <<-EOF &&
239 command=ls-refs
240 object-format=$(test_oid algo)
241 0001
242 peel
243 ref-prefix refs/tags/
244 0000
247 cat >expect <<-EOF &&
248 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
249 $(git rev-parse refs/tags/one) refs/tags/one
250 $(git rev-parse refs/tags/two) refs/tags/two
251 0000
254 test-tool serve-v2 --stateless-rpc <in >out &&
255 test-tool pkt-line unpack <out >actual &&
256 test_cmp expect actual
259 test_expect_success 'symrefs parameter' '
260 test-tool pkt-line pack >in <<-EOF &&
261 command=ls-refs
262 object-format=$(test_oid algo)
263 0001
264 symrefs
265 ref-prefix refs/heads/
266 0000
269 cat >expect <<-EOF &&
270 $(git rev-parse refs/heads/dev) refs/heads/dev
271 $(git rev-parse refs/heads/main) refs/heads/main
272 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
273 0000
276 test-tool serve-v2 --stateless-rpc <in >out &&
277 test-tool pkt-line unpack <out >actual &&
278 test_cmp expect actual
281 test_expect_success 'sending server-options' '
282 test-tool pkt-line pack >in <<-EOF &&
283 command=ls-refs
284 object-format=$(test_oid algo)
285 server-option=hello
286 server-option=world
287 0001
288 ref-prefix HEAD
289 0000
292 cat >expect <<-EOF &&
293 $(git rev-parse HEAD) HEAD
294 0000
297 test-tool serve-v2 --stateless-rpc <in >out &&
298 test-tool pkt-line unpack <out >actual &&
299 test_cmp expect actual
302 test_expect_success 'unexpected lines are not allowed in fetch request' '
303 git init server &&
305 test-tool pkt-line pack >in <<-EOF &&
306 command=fetch
307 object-format=$(test_oid algo)
308 0001
309 this-is-not-a-command
310 0000
314 cd server &&
315 test_must_fail test-tool serve-v2 --stateless-rpc
316 ) <in >/dev/null 2>err &&
317 grep "unexpected line: .this-is-not-a-command." err
320 # Test the basics of object-info
322 test_expect_success 'basics of object-info' '
323 test-tool pkt-line pack >in <<-EOF &&
324 command=object-info
325 object-format=$(test_oid algo)
326 0001
327 size
328 oid $(git rev-parse two:two.t)
329 oid $(git rev-parse two:two.t)
330 0000
333 cat >expect <<-EOF &&
334 size
335 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
336 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
337 0000
340 test-tool serve-v2 --stateless-rpc <in >out &&
341 test-tool pkt-line unpack <out >actual &&
342 test_cmp expect actual
345 test_done