3 test_description
='test protocol v2 server commands'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'test capability advertisement' '
11 test_oid_cache <<-EOF &&
12 wrong_algo sha1:sha256
13 wrong_algo sha256:sha1
17 agent=git/$(git version | cut -d" " -f3)
19 fetch=shallow wait-for-done
21 object-format=$(test_oid algo)
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' '
34 test-tool pkt-line pack >in <<-EOF &&
37 test-tool serve-v2 --stateless-rpc >out <in &&
38 test_must_be_empty out &&
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 &&
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 &&
57 object-format=$(test_oid algo)
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 &&
67 object-format=$(test_oid algo)
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 &&
78 object-format=$(test_oid algo)
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 &&
88 object-format=$(test_oid algo)
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)
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 &&
110 object-format=$(test_oid wrong_algo)
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' '
121 git branch dev main &&
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 &&
130 object-format=$(test_oid algo)
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
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 &&
153 object-format=$(test_oid algo)
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 &&
166 object-format=$(test_oid algo)
168 ref-prefix refs/heads/main
169 ref-prefix refs/tags/one
173 cat >expect <<-EOF &&
174 $(git rev-parse refs/heads/main) refs/heads/main
175 $(git rev-parse refs/tags/one) refs/tags/one
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 &&
187 object-format=$(test_oid algo)
189 ref-prefix refs/heads/
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
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
210 echo command=ls-refs &&
211 echo object-format=$(test_oid algo) &&
213 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
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
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 &&
239 object-format=$(test_oid algo)
242 ref-prefix refs/tags/
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
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 &&
261 object-format=$(test_oid algo)
264 ref-prefix refs/heads/
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
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 &&
283 object-format=$(test_oid algo)
291 cat >expect <<-EOF &&
292 $(git rev-parse HEAD) HEAD
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' '
304 test-tool pkt-line pack >in <<-EOF &&
306 object-format=$(test_oid algo)
308 this-is-not-a-command
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 &&
324 object-format=$(test_oid algo)
327 oid $(git rev-parse two:two.t)
328 oid $(git rev-parse two:two.t)
332 cat >expect <<-EOF &&
334 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
335 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
339 test-tool serve-v2 --stateless-rpc <in >out &&
340 test-tool pkt-line unpack <out >actual &&
341 test_cmp expect actual