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
11 test_expect_success
'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
18 agent=git/$(git version | cut -d" " -f3)
20 fetch=shallow wait-for-done
22 object-format=$(test_oid algo)
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' '
35 test-tool pkt-line pack >in <<-EOF &&
38 test-tool serve-v2 --stateless-rpc >out <in &&
39 test_must_be_empty out &&
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 &&
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 &&
58 object-format=$(test_oid algo)
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 &&
68 object-format=$(test_oid algo)
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 &&
79 object-format=$(test_oid algo)
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 &&
89 object-format=$(test_oid algo)
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)
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 &&
111 object-format=$(test_oid wrong_algo)
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' '
122 git branch dev main &&
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 &&
131 object-format=$(test_oid algo)
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
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 &&
154 object-format=$(test_oid algo)
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 &&
167 object-format=$(test_oid algo)
169 ref-prefix refs/heads/main
170 ref-prefix refs/tags/one
174 cat >expect <<-EOF &&
175 $(git rev-parse refs/heads/main) refs/heads/main
176 $(git rev-parse refs/tags/one) refs/tags/one
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 &&
188 object-format=$(test_oid algo)
190 ref-prefix refs/heads/
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
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
211 echo command=ls-refs &&
212 echo object-format=$(test_oid algo) &&
214 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
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
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 &&
240 object-format=$(test_oid algo)
243 ref-prefix refs/tags/
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
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 &&
262 object-format=$(test_oid algo)
265 ref-prefix refs/heads/
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
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 &&
284 object-format=$(test_oid algo)
292 cat >expect <<-EOF &&
293 $(git rev-parse HEAD) HEAD
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' '
305 test-tool pkt-line pack >in <<-EOF &&
307 object-format=$(test_oid algo)
309 this-is-not-a-command
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 &&
325 object-format=$(test_oid algo)
328 oid $(git rev-parse two:two.t)
329 oid $(git rev-parse two:two.t)
333 cat >expect <<-EOF &&
335 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
336 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
340 test-tool serve-v2 --stateless-rpc <in >out &&
341 test-tool pkt-line unpack <out >actual &&
342 test_cmp expect actual