reset: make sparse-aware (except --mixed)
[git.git] / t / t5701-git-serve.sh
blobaa1827d841d47779ef3bb081aba8205802395fb2
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-lib.sh
10 test_expect_success 'test capability advertisement' '
11 test_oid_cache <<-EOF &&
12 wrong_algo sha1:sha256
13 wrong_algo sha256:sha1
14 EOF
15 cat >expect <<-EOF &&
16 version 2
17 agent=git/$(git version | cut -d" " -f3)
18 ls-refs=unborn
19 fetch=shallow wait-for-done
20 server-option
21 object-format=$(test_oid algo)
22 object-info
23 0000
24 EOF
26 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
27 --advertise-capabilities >out &&
28 test-tool pkt-line unpack <out >actual &&
29 test_cmp expect actual
32 test_expect_success 'stateless-rpc flag does not list capabilities' '
33 # Empty request
34 test-tool pkt-line pack >in <<-EOF &&
35 0000
36 EOF
37 test-tool serve-v2 --stateless-rpc >out <in &&
38 test_must_be_empty out &&
40 # EOF
41 test-tool serve-v2 --stateless-rpc >out &&
42 test_must_be_empty out
45 test_expect_success 'request invalid capability' '
46 test-tool pkt-line pack >in <<-EOF &&
47 foobar
48 0000
49 EOF
50 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
51 test_i18ngrep "unknown capability" err
54 test_expect_success 'request with no command' '
55 test-tool pkt-line pack >in <<-EOF &&
56 agent=git/test
57 object-format=$(test_oid algo)
58 0000
59 EOF
60 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
61 test_i18ngrep "no command requested" err
64 test_expect_success 'request invalid command' '
65 test-tool pkt-line pack >in <<-EOF &&
66 command=foo
67 object-format=$(test_oid algo)
68 agent=git/test
69 0000
70 EOF
71 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
72 test_i18ngrep "invalid command" err
75 test_expect_success 'request capability as command' '
76 test-tool pkt-line pack >in <<-EOF &&
77 command=agent
78 object-format=$(test_oid algo)
79 0000
80 EOF
81 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
82 grep invalid.command.*agent err
85 test_expect_success 'request command as capability' '
86 test-tool pkt-line pack >in <<-EOF &&
87 command=ls-refs
88 object-format=$(test_oid algo)
89 fetch
90 0000
91 EOF
92 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
93 grep unknown.capability err
96 test_expect_success 'requested command is command=value' '
97 test-tool pkt-line pack >in <<-EOF &&
98 command=ls-refs=whatever
99 object-format=$(test_oid algo)
100 0000
102 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
103 grep invalid.command.*ls-refs=whatever err
106 test_expect_success 'wrong object-format' '
107 test-tool pkt-line pack >in <<-EOF &&
108 command=fetch
109 agent=git/test
110 object-format=$(test_oid wrong_algo)
111 0000
113 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
114 test_i18ngrep "mismatched object format" err
117 # Test the basics of ls-refs
119 test_expect_success 'setup some refs and tags' '
120 test_commit one &&
121 git branch dev main &&
122 test_commit two &&
123 git symbolic-ref refs/heads/release refs/heads/main &&
124 git tag -a -m "annotated tag" annotated-tag
127 test_expect_success 'basics of ls-refs' '
128 test-tool pkt-line pack >in <<-EOF &&
129 command=ls-refs
130 object-format=$(test_oid algo)
131 0000
134 cat >expect <<-EOF &&
135 $(git rev-parse HEAD) HEAD
136 $(git rev-parse refs/heads/dev) refs/heads/dev
137 $(git rev-parse refs/heads/main) refs/heads/main
138 $(git rev-parse refs/heads/release) refs/heads/release
139 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
140 $(git rev-parse refs/tags/one) refs/tags/one
141 $(git rev-parse refs/tags/two) refs/tags/two
142 0000
145 test-tool serve-v2 --stateless-rpc <in >out &&
146 test-tool pkt-line unpack <out >actual &&
147 test_cmp expect actual
150 test_expect_success 'ls-refs complains about unknown options' '
151 test-tool pkt-line pack >in <<-EOF &&
152 command=ls-refs
153 object-format=$(test_oid algo)
154 0001
155 no-such-arg
156 0000
159 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
160 grep unexpected.line.*no-such-arg err
163 test_expect_success 'basic ref-prefixes' '
164 test-tool pkt-line pack >in <<-EOF &&
165 command=ls-refs
166 object-format=$(test_oid algo)
167 0001
168 ref-prefix refs/heads/main
169 ref-prefix refs/tags/one
170 0000
173 cat >expect <<-EOF &&
174 $(git rev-parse refs/heads/main) refs/heads/main
175 $(git rev-parse refs/tags/one) refs/tags/one
176 0000
179 test-tool serve-v2 --stateless-rpc <in >out &&
180 test-tool pkt-line unpack <out >actual &&
181 test_cmp expect actual
184 test_expect_success 'refs/heads prefix' '
185 test-tool pkt-line pack >in <<-EOF &&
186 command=ls-refs
187 object-format=$(test_oid algo)
188 0001
189 ref-prefix refs/heads/
190 0000
193 cat >expect <<-EOF &&
194 $(git rev-parse refs/heads/dev) refs/heads/dev
195 $(git rev-parse refs/heads/main) refs/heads/main
196 $(git rev-parse refs/heads/release) refs/heads/release
197 0000
200 test-tool serve-v2 --stateless-rpc <in >out &&
201 test-tool pkt-line unpack <out >actual &&
202 test_cmp expect actual
205 test_expect_success 'ignore very large set of prefixes' '
206 # generate a large number of ref-prefixes that we expect
207 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
208 # from ls-refs.c.
210 echo command=ls-refs &&
211 echo object-format=$(test_oid algo) &&
212 echo 0001 &&
213 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
214 echo 0000
216 test-tool pkt-line pack >in &&
218 # and then confirm that we see unmatched prefixes anyway (i.e.,
219 # that the prefix was not applied).
220 cat >expect <<-EOF &&
221 $(git rev-parse HEAD) HEAD
222 $(git rev-parse refs/heads/dev) refs/heads/dev
223 $(git rev-parse refs/heads/main) refs/heads/main
224 $(git rev-parse refs/heads/release) refs/heads/release
225 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
226 $(git rev-parse refs/tags/one) refs/tags/one
227 $(git rev-parse refs/tags/two) refs/tags/two
228 0000
231 test-tool serve-v2 --stateless-rpc <in >out &&
232 test-tool pkt-line unpack <out >actual &&
233 test_cmp expect actual
236 test_expect_success 'peel parameter' '
237 test-tool pkt-line pack >in <<-EOF &&
238 command=ls-refs
239 object-format=$(test_oid algo)
240 0001
241 peel
242 ref-prefix refs/tags/
243 0000
246 cat >expect <<-EOF &&
247 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
248 $(git rev-parse refs/tags/one) refs/tags/one
249 $(git rev-parse refs/tags/two) refs/tags/two
250 0000
253 test-tool serve-v2 --stateless-rpc <in >out &&
254 test-tool pkt-line unpack <out >actual &&
255 test_cmp expect actual
258 test_expect_success 'symrefs parameter' '
259 test-tool pkt-line pack >in <<-EOF &&
260 command=ls-refs
261 object-format=$(test_oid algo)
262 0001
263 symrefs
264 ref-prefix refs/heads/
265 0000
268 cat >expect <<-EOF &&
269 $(git rev-parse refs/heads/dev) refs/heads/dev
270 $(git rev-parse refs/heads/main) refs/heads/main
271 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
272 0000
275 test-tool serve-v2 --stateless-rpc <in >out &&
276 test-tool pkt-line unpack <out >actual &&
277 test_cmp expect actual
280 test_expect_success 'sending server-options' '
281 test-tool pkt-line pack >in <<-EOF &&
282 command=ls-refs
283 object-format=$(test_oid algo)
284 server-option=hello
285 server-option=world
286 0001
287 ref-prefix HEAD
288 0000
291 cat >expect <<-EOF &&
292 $(git rev-parse HEAD) HEAD
293 0000
296 test-tool serve-v2 --stateless-rpc <in >out &&
297 test-tool pkt-line unpack <out >actual &&
298 test_cmp expect actual
301 test_expect_success 'unexpected lines are not allowed in fetch request' '
302 git init server &&
304 test-tool pkt-line pack >in <<-EOF &&
305 command=fetch
306 object-format=$(test_oid algo)
307 0001
308 this-is-not-a-command
309 0000
313 cd server &&
314 test_must_fail test-tool serve-v2 --stateless-rpc
315 ) <in >/dev/null 2>err &&
316 grep "unexpected line: .this-is-not-a-command." err
319 # Test the basics of object-info
321 test_expect_success 'basics of object-info' '
322 test-tool pkt-line pack >in <<-EOF &&
323 command=object-info
324 object-format=$(test_oid algo)
325 0001
326 size
327 oid $(git rev-parse two:two.t)
328 oid $(git rev-parse two:two.t)
329 0000
332 cat >expect <<-EOF &&
333 size
334 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
335 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
336 0000
339 test-tool serve-v2 --stateless-rpc <in >out &&
340 test-tool pkt-line unpack <out >actual &&
341 test_cmp expect actual
344 test_done