1
+#!/bin/sh
2
+
3
+test_description='git cat-file --batch-command with remote-object-info command'
4
+
5
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
+
8
+. ./test-lib.sh
9
+. "$TEST_DIRECTORY"/lib-cat-file.sh
10
+
11
+hello_content="Hello World"
12
+hello_size=$(strlen "$hello_content")
13
+hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
14
+hello_short_oid=$(git rev-parse --short "$hello_oid")
15
+
16
+unstored_content="Hello Git"
17
+unstored_oid=$(echo_without_newline "$unstored_content" | git hash-object --stdin)
18
+
19
+# This is how we get 13:
20
+# 13 = <file mode> + <a_space> + <file name> + <a_null>, where
21
+# file mode is 100644, which is 6 characters;
22
+# file name is hello, which is 5 characters
23
+# a space is 1 character and a null is 1 character
24
+tree_size=$(($(test_oid rawsz) + 13))
25
+
26
+commit_message="Initial commit"
27
+
28
+# This is how we get 137:
29
+# 137 = <tree header> + <a_space> + <a newline> +
30
+# <Author line> + <a newline> +
31
+# <Committer line> + <a newline> +
32
+# <a newline> +
33
+# <commit message length>
34
+# An easier way to calculate is: 1. use `git cat-file commit <commit hash> | wc -c`,
35
+# to get 177, 2. then deduct 40 hex characters to get 137
36
+commit_size=$(($(test_oid hexsz) + 137))
37
+
38
+tag_header_without_oid="type blob
39
+tag hellotag
40
+tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
41
+tag_header_without_timestamp="object $hello_oid
42
+$tag_header_without_oid"
43
+tag_description="This is a tag"
44
+tag_content="$tag_header_without_timestamp 0 +0000
45
+
46
+$tag_description"
47
+
48
+tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
49
+tag_size=$(strlen "$tag_content")
50
+
51
+set_transport_variables () {
52
+ hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
53
+ tree_oid=$(git -C "$1" write-tree)
54
+ commit_oid=$(echo_without_newline "$commit_message" | git -C "$1" commit-tree $tree_oid)
55
+ tag_oid=$(echo_without_newline "$tag_content" | git -C "$1" hash-object -t tag --stdin -w)
56
+ tag_size=$(strlen "$tag_content")
57
+}
58
+
59
+# This section tests --batch-command with remote-object-info command
60
+# Since "%(objecttype)" is currently not supported by the command remote-object-info ,
61
+# the filters are set to "%(objectname) %(objectsize)" in some test cases.
62
+
63
+# Test --batch-command remote-object-info with 'git://' transport with
64
+# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
65
+. "$TEST_DIRECTORY"/lib-git-daemon.sh
66
+start_git_daemon --export-all --enable=receive-pack
67
+daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
68
+
69
+test_expect_success 'create repo to be served by git-daemon' '
70
+ git init "$daemon_parent" &&
71
+ echo_without_newline "$hello_content" > $daemon_parent/hello &&
72
+ git -C "$daemon_parent" update-index --add hello &&
73
+ git -C "$daemon_parent" config transfer.advertiseobjectinfo true &&
74
+ git clone "$GIT_DAEMON_URL/parent" -n "$daemon_parent/daemon_client_empty"
75
+'
76
+
77
+test_expect_success 'batch-command remote-object-info git://' '
78
+ (
79
+ set_transport_variables "$daemon_parent" &&
80
+ cd "$daemon_parent/daemon_client_empty" &&
81
+
82
+ # These results prove remote-object-info can get object info from the remote
83
+ echo "$hello_oid $hello_size" >expect &&
84
+ echo "$tree_oid $tree_size" >>expect &&
85
+ echo "$commit_oid $commit_size" >>expect &&
86
+ echo "$tag_oid $tag_size" >>expect &&
87
+
88
+ # These results prove remote-object-info did not download objects from the remote
89
+ echo "$hello_oid missing" >>expect &&
90
+ echo "$tree_oid missing" >>expect &&
91
+ echo "$commit_oid missing" >>expect &&
92
+ echo "$tag_oid missing" >>expect &&
93
+
94
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
95
+ remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
96
+ remote-object-info "$GIT_DAEMON_URL/parent" $tree_oid
97
+ remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid
98
+ remote-object-info "$GIT_DAEMON_URL/parent" $tag_oid
99
+ info $hello_oid
100
+ info $tree_oid
101
+ info $commit_oid
102
+ info $tag_oid
103
+ EOF
104
+ test_cmp expect actual
105
+ )
106
+'
107
+
108
+test_expect_success 'batch-command remote-object-info git:// multiple sha1 per line' '
109
+ (
110
+ set_transport_variables "$daemon_parent" &&
111
+ cd "$daemon_parent/daemon_client_empty" &&
112
+
113
+ # These results prove remote-object-info can get object info from the remote
114
+ echo "$hello_oid $hello_size" >expect &&
115
+ echo "$tree_oid $tree_size" >>expect &&
116
+ echo "$commit_oid $commit_size" >>expect &&
117
+ echo "$tag_oid $tag_size" >>expect &&
118
+
119
+ # These results prove remote-object-info did not download objects from the remote
120
+ echo "$hello_oid missing" >>expect &&
121
+ echo "$tree_oid missing" >>expect &&
122
+ echo "$commit_oid missing" >>expect &&
123
+ echo "$tag_oid missing" >>expect &&
124
+
125
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
126
+ remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid $commit_oid $tag_oid
127
+ info $hello_oid
128
+ info $tree_oid
129
+ info $commit_oid
130
+ info $tag_oid
131
+ EOF
132
+ test_cmp expect actual
133
+ )
134
+'
135
+
136
+test_expect_success 'batch-command remote-object-info git:// default filter' '
137
+ (
138
+ set_transport_variables "$daemon_parent" &&
139
+ cd "$daemon_parent/daemon_client_empty" &&
140
+
141
+ echo "$hello_oid $hello_size" >expect &&
142
+ echo "$tree_oid $tree_size" >>expect &&
143
+ echo "$commit_oid $commit_size" >>expect &&
144
+ echo "$tag_oid $tag_size" >>expect &&
145
+ GIT_TRACE_PACKET=1 git cat-file --batch-command >actual <<-EOF &&
146
+ remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
147
+ remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid
148
+ EOF
149
+ test_cmp expect actual
150
+ )
151
+'
152
+
153
+test_expect_success 'batch-command --buffer remote-object-info git://' '
154
+ (
155
+ set_transport_variables "$daemon_parent" &&
156
+ cd "$daemon_parent/daemon_client_empty" &&
157
+
158
+ # These results prove remote-object-info can get object info from the remote
159
+ echo "$hello_oid $hello_size" >expect &&
160
+ echo "$tree_oid $tree_size" >>expect &&
161
+ echo "$commit_oid $commit_size" >>expect &&
162
+ echo "$tag_oid $tag_size" >>expect &&
163
+
164
+ # These results prove remote-object-info did not download objects from the remote
165
+ echo "$hello_oid missing" >>expect &&
166
+ echo "$tree_oid missing" >>expect &&
167
+ echo "$commit_oid missing" >>expect &&
168
+ echo "$tag_oid missing" >>expect &&
169
+
170
+ git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
171
+ remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
172
+ remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid
173
+ info $hello_oid
174
+ info $tree_oid
175
+ info $commit_oid
176
+ info $tag_oid
177
+ flush
178
+ EOF
179
+ test_cmp expect actual
180
+ )
181
+'
182
+
183
+test_expect_success 'batch-command -Z remote-object-info git:// default filter' '
184
+ (
185
+ set_transport_variables "$daemon_parent" &&
186
+ cd "$daemon_parent/daemon_client_empty" &&
187
+
188
+ printf "%s\0" "$hello_oid $hello_size" >expect &&
189
+ printf "%s\0" "$tree_oid $tree_size" >>expect &&
190
+ printf "%s\0" "$commit_oid $commit_size" >>expect &&
191
+ printf "%s\0" "$tag_oid $tag_size" >>expect &&
192
+
193
+ printf "%s\0" "$hello_oid missing" >>expect &&
194
+ printf "%s\0" "$tree_oid missing" >>expect &&
195
+ printf "%s\0" "$commit_oid missing" >>expect &&
196
+ printf "%s\0" "$tag_oid missing" >>expect &&
197
+
198
+ batch_input="remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid
199
+remote-object-info $GIT_DAEMON_URL/parent $commit_oid $tag_oid
200
+info $hello_oid
201
+info $tree_oid
202
+info $commit_oid
203
+info $tag_oid
204
+" &&
205
+ echo_without_newline_nul "$batch_input" >commands_null_delimited &&
206
+
207
+ git cat-file --batch-command -Z < commands_null_delimited >actual &&
208
+ test_cmp expect actual
209
+ )
210
+'
211
+
212
+test_expect_success 'remote-object-info does not support short oids' '
213
+ (
214
+ set_transport_variables "$daemon_parent" &&
215
+ cd "$daemon_parent/daemon_client_empty" &&
216
+
217
+ test_must_fail git cat-file --batch-command 2>err <<-EOF &&
218
+ remote-object-info $GIT_DAEMON_URL/parent $hello_short_oid
219
+ EOF
220
+ test_grep "does not support short oids" err
221
+ )
222
+'
223
+
224
+test_expect_success 'remote-object-info does not die on missing oid like info' '
225
+ (
226
+ set_transport_variables "$daemon_parent" &&
227
+ cd "$daemon_parent/daemon_client_empty" &&
228
+
229
+ git cat-file --batch-command >local <<-EOF &&
230
+ info $unstored_oid
231
+ EOF
232
+ git cat-file --batch-command >remote <<-EOF &&
233
+ remote-object-info $GIT_DAEMON_URL/parent $unstored_oid
234
+ EOF
235
+ test_cmp local remote
236
+ )
237
+'
238
+
239
+# Test --batch-command remote-object-info with 'git://' and
240
+# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
241
+test_expect_success 'batch-command remote-object-info git:// fails when transfer.advertiseobjectinfo=false' '
242
+ (
243
+ git -C "$daemon_parent" config transfer.advertiseobjectinfo false &&
244
+ set_transport_variables "$daemon_parent" &&
245
+
246
+ test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
247
+ remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid $commit_oid $tag_oid
248
+ EOF
249
+ test_grep "object-info capability is not enabled on the server" err &&
250
+
251
+ # revert server state back
252
+ git -C "$daemon_parent" config transfer.advertiseobjectinfo true
253
+
254
+ )
255
+'
256
+
257
+stop_git_daemon
258
+
259
+# Test --batch-command remote-object-info with 'file://' transport with
260
+# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
261
+# shellcheck disable=SC2016
262
+test_expect_success 'create repo to be served by file:// transport' '
263
+ git init server &&
264
+ git -C server config protocol.version 2 &&
265
+ git -C server config transfer.advertiseobjectinfo true &&
266
+ echo_without_newline "$hello_content" > server/hello &&
267
+ git -C server update-index --add hello &&
268
+ git clone -n "file://$(pwd)/server" file_client_empty
269
+'
270
+
271
+test_expect_success 'batch-command remote-object-info file://' '
272
+ (
273
+ set_transport_variables "server" &&
274
+ server_path="$(pwd)/server" &&
275
+ cd file_client_empty &&
276
+
277
+ # These results prove remote-object-info can get object info from the remote
278
+ echo "$hello_oid $hello_size" >expect &&
279
+ echo "$tree_oid $tree_size" >>expect &&
280
+ echo "$commit_oid $commit_size" >>expect &&
281
+ echo "$tag_oid $tag_size" >>expect &&
282
+
283
+ # These results prove remote-object-info did not download objects from the remote
284
+ echo "$hello_oid missing" >>expect &&
285
+ echo "$tree_oid missing" >>expect &&
286
+ echo "$commit_oid missing" >>expect &&
287
+ echo "$tag_oid missing" >>expect &&
288
+
289
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
290
+ remote-object-info "file://${server_path}" $hello_oid
291
+ remote-object-info "file://${server_path}" $tree_oid
292
+ remote-object-info "file://${server_path}" $commit_oid
293
+ remote-object-info "file://${server_path}" $tag_oid
294
+ info $hello_oid
295
+ info $tree_oid
296
+ info $commit_oid
297
+ info $tag_oid
298
+ EOF
299
+ test_cmp expect actual
300
+ )
301
+'
302
+
303
+test_expect_success 'batch-command remote-object-info file:// multiple sha1 per line' '
304
+ (
305
+ set_transport_variables "server" &&
306
+ server_path="$(pwd)/server" &&
307
+ cd file_client_empty &&
308
+
309
+ # These results prove remote-object-info can get object info from the remote
310
+ echo "$hello_oid $hello_size" >expect &&
311
+ echo "$tree_oid $tree_size" >>expect &&
312
+ echo "$commit_oid $commit_size" >>expect &&
313
+ echo "$tag_oid $tag_size" >>expect &&
314
+
315
+ # These results prove remote-object-info did not download objects from the remote
316
+ echo "$hello_oid missing" >>expect &&
317
+ echo "$tree_oid missing" >>expect &&
318
+ echo "$commit_oid missing" >>expect &&
319
+ echo "$tag_oid missing" >>expect &&
320
+
321
+
322
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
323
+ remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid
324
+ info $hello_oid
325
+ info $tree_oid
326
+ info $commit_oid
327
+ info $tag_oid
328
+ EOF
329
+ test_cmp expect actual
330
+ )
331
+'
332
+
333
+test_expect_success 'batch-command --buffer remote-object-info file://' '
334
+ (
335
+ set_transport_variables "server" &&
336
+ server_path="$(pwd)/server" &&
337
+ cd file_client_empty &&
338
+
339
+ # These results prove remote-object-info can get object info from the remote
340
+ echo "$hello_oid $hello_size" >expect &&
341
+ echo "$tree_oid $tree_size" >>expect &&
342
+ echo "$commit_oid $commit_size" >>expect &&
343
+ echo "$tag_oid $tag_size" >>expect &&
344
+
345
+ # These results prove remote-object-info did not download objects from the remote
346
+ echo "$hello_oid missing" >>expect &&
347
+ echo "$tree_oid missing" >>expect &&
348
+ echo "$commit_oid missing" >>expect &&
349
+ echo "$tag_oid missing" >>expect &&
350
+
351
+ git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
352
+ remote-object-info "file://${server_path}" $hello_oid $tree_oid
353
+ remote-object-info "file://${server_path}" $commit_oid $tag_oid
354
+ info $hello_oid
355
+ info $tree_oid
356
+ info $commit_oid
357
+ info $tag_oid
358
+ flush
359
+ EOF
360
+ test_cmp expect actual
361
+ )
362
+'
363
+
364
+test_expect_success 'batch-command remote-object-info file:// default filter' '
365
+ (
366
+ set_transport_variables "server" &&
367
+ server_path="$(pwd)/server" &&
368
+ cd file_client_empty &&
369
+
370
+ echo "$hello_oid $hello_size" >expect &&
371
+ echo "$tree_oid $tree_size" >>expect &&
372
+ echo "$commit_oid $commit_size" >>expect &&
373
+ echo "$tag_oid $tag_size" >>expect &&
374
+
375
+ git cat-file --batch-command >actual <<-EOF &&
376
+ remote-object-info "file://${server_path}" $hello_oid $tree_oid
377
+ remote-object-info "file://${server_path}" $commit_oid $tag_oid
378
+ EOF
379
+ test_cmp expect actual
380
+ )
381
+'
382
+
383
+test_expect_success 'batch-command -Z remote-object-info file:// default filter' '
384
+ (
385
+ set_transport_variables "server" &&
386
+ server_path="$(pwd)/server" &&
387
+ cd file_client_empty &&
388
+
389
+ printf "%s\0" "$hello_oid $hello_size" >expect &&
390
+ printf "%s\0" "$tree_oid $tree_size" >>expect &&
391
+ printf "%s\0" "$commit_oid $commit_size" >>expect &&
392
+ printf "%s\0" "$tag_oid $tag_size" >>expect &&
393
+
394
+ printf "%s\0" "$hello_oid missing" >>expect &&
395
+ printf "%s\0" "$tree_oid missing" >>expect &&
396
+ printf "%s\0" "$commit_oid missing" >>expect &&
397
+ printf "%s\0" "$tag_oid missing" >>expect &&
398
+
399
+ batch_input="remote-object-info \"file://${server_path}\" $hello_oid $tree_oid
400
+remote-object-info \"file://${server_path}\" $commit_oid $tag_oid
401
+info $hello_oid
402
+info $tree_oid
403
+info $commit_oid
404
+info $tag_oid
405
+" &&
406
+ echo_without_newline_nul "$batch_input" >commands_null_delimited &&
407
+
408
+ git cat-file --batch-command -Z < commands_null_delimited >actual &&
409
+ test_cmp expect actual
410
+ )
411
+'
412
+
413
+# Test --batch-command remote-object-info with 'file://' and
414
+# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
415
+test_expect_success 'batch-command remote-object-info file:// fails when transfer.advertiseobjectinfo=false' '
416
+ (
417
+ set_transport_variables "server" &&
418
+ server_path="$(pwd)/server" &&
419
+ git -C "${server_path}" config transfer.advertiseobjectinfo false &&
420
+
421
+ test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
422
+ remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid
423
+ EOF
424
+ test_grep "object-info capability is not enabled on the server" err &&
425
+
426
+ # revert server state back
427
+ git -C "${server_path}" config transfer.advertiseobjectinfo true
428
+ )
429
+'
430
+
431
+# Test --batch-command remote-object-info with 'http://' transport with
432
+# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
433
+
434
+. "$TEST_DIRECTORY"/lib-httpd.sh
435
+start_httpd
436
+
437
+test_expect_success 'create repo to be served by http:// transport' '
438
+ git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
439
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
440
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true &&
441
+ echo_without_newline "$hello_content" > $HTTPD_DOCUMENT_ROOT_PATH/http_parent/hello &&
442
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" update-index --add hello &&
443
+ git clone "$HTTPD_URL/smart/http_parent" -n "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty"
444
+'
445
+
446
+test_expect_success 'batch-command remote-object-info http://' '
447
+ (
448
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
449
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
450
+
451
+ # These results prove remote-object-info can get object info from the remote
452
+ echo "$hello_oid $hello_size" >expect &&
453
+ echo "$tree_oid $tree_size" >>expect &&
454
+ echo "$commit_oid $commit_size" >>expect &&
455
+ echo "$tag_oid $tag_size" >>expect &&
456
+
457
+ # These results prove remote-object-info did not download objects from the remote
458
+ echo "$hello_oid missing" >>expect &&
459
+ echo "$tree_oid missing" >>expect &&
460
+ echo "$commit_oid missing" >>expect &&
461
+ echo "$tag_oid missing" >>expect &&
462
+
463
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
464
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
465
+ remote-object-info "$HTTPD_URL/smart/http_parent" $tree_oid
466
+ remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid
467
+ remote-object-info "$HTTPD_URL/smart/http_parent" $tag_oid
468
+ info $hello_oid
469
+ info $tree_oid
470
+ info $commit_oid
471
+ info $tag_oid
472
+ EOF
473
+ test_cmp expect actual
474
+ )
475
+'
476
+
477
+test_expect_success 'batch-command remote-object-info http:// one line' '
478
+ (
479
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
480
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
481
+
482
+ # These results prove remote-object-info can get object info from the remote
483
+ echo "$hello_oid $hello_size" >expect &&
484
+ echo "$tree_oid $tree_size" >>expect &&
485
+ echo "$commit_oid $commit_size" >>expect &&
486
+ echo "$tag_oid $tag_size" >>expect &&
487
+
488
+ # These results prove remote-object-info did not download objects from the remote
489
+ echo "$hello_oid missing" >>expect &&
490
+ echo "$tree_oid missing" >>expect &&
491
+ echo "$commit_oid missing" >>expect &&
492
+ echo "$tag_oid missing" >>expect &&
493
+
494
+ git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
495
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid
496
+ info $hello_oid
497
+ info $tree_oid
498
+ info $commit_oid
499
+ info $tag_oid
500
+ EOF
501
+ test_cmp expect actual
502
+ )
503
+'
504
+
505
+test_expect_success 'batch-command --buffer remote-object-info http://' '
506
+ (
507
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
508
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
509
+
510
+ # These results prove remote-object-info can get object info from the remote
511
+ echo "$hello_oid $hello_size" >expect &&
512
+ echo "$tree_oid $tree_size" >>expect &&
513
+ echo "$commit_oid $commit_size" >>expect &&
514
+ echo "$tag_oid $tag_size" >>expect &&
515
+
516
+ # These results prove remote-object-info did not download objects from the remote
517
+ echo "$hello_oid missing" >>expect &&
518
+ echo "$tree_oid missing" >>expect &&
519
+ echo "$commit_oid missing" >>expect &&
520
+ echo "$tag_oid missing" >>expect &&
521
+
522
+ git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
523
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
524
+ remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid
525
+ info $hello_oid
526
+ info $tree_oid
527
+ info $commit_oid
528
+ info $tag_oid
529
+ flush
530
+ EOF
531
+ test_cmp expect actual
532
+ )
533
+'
534
+
535
+test_expect_success 'batch-command remote-object-info http:// default filter' '
536
+ (
537
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
538
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
539
+
540
+ echo "$hello_oid $hello_size" >expect &&
541
+ echo "$tree_oid $tree_size" >>expect &&
542
+ echo "$commit_oid $commit_size" >>expect &&
543
+ echo "$tag_oid $tag_size" >>expect &&
544
+
545
+ git cat-file --batch-command >actual <<-EOF &&
546
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
547
+ remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid
548
+ EOF
549
+ test_cmp expect actual
550
+ )
551
+'
552
+
553
+test_expect_success 'batch-command -Z remote-object-info http:// default filter' '
554
+ (
555
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
556
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
557
+
558
+ printf "%s\0" "$hello_oid $hello_size" >expect &&
559
+ printf "%s\0" "$tree_oid $tree_size" >>expect &&
560
+ printf "%s\0" "$commit_oid $commit_size" >>expect &&
561
+ printf "%s\0" "$tag_oid $tag_size" >>expect &&
562
+
563
+ batch_input="remote-object-info $HTTPD_URL/smart/http_parent $hello_oid $tree_oid
564
+remote-object-info $HTTPD_URL/smart/http_parent $commit_oid $tag_oid
565
+" &&
566
+ echo_without_newline_nul "$batch_input" >commands_null_delimited &&
567
+
568
+ git cat-file --batch-command -Z < commands_null_delimited >actual &&
569
+ test_cmp expect actual
570
+ )
571
+'
572
+
573
+test_expect_success 'remote-object-info fails on unsupported filter option (objectsize:disk)' '
574
+ (
575
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
576
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
577
+
578
+ test_must_fail git cat-file --batch-command="%(objectsize:disk)" 2>err <<-EOF &&
579
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
580
+ EOF
581
+ test_grep "%(objectsize:disk) is currently not supported with remote-object-info" err
582
+ )
583
+'
584
+
585
+test_expect_success 'remote-object-info fails on unsupported filter option (deltabase)' '
586
+ (
587
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
588
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
589
+
590
+ test_must_fail git cat-file --batch-command="%(deltabase)" 2>err <<-EOF &&
591
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
592
+ EOF
593
+ test_grep "%(deltabase) is currently not supported with remote-object-info" err
594
+ )
595
+'
596
+
597
+test_expect_success 'remote-object-info fails on server with legacy protocol' '
598
+ (
599
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
600
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
601
+
602
+ test_must_fail git -c protocol.version=0 cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
603
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
604
+ EOF
605
+ test_grep "object-info requires protocol v2" err
606
+ )
607
+'
608
+
609
+test_expect_success 'remote-object-info fails on server with legacy protocol with default filter' '
610
+ (
611
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
612
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
613
+
614
+ test_must_fail git -c protocol.version=0 cat-file --batch-command 2>err <<-EOF &&
615
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
616
+ EOF
617
+ test_grep "object-info requires protocol v2" err
618
+ )
619
+'
620
+
621
+test_expect_success 'remote-object-info fails on malformed OID' '
622
+ (
623
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
624
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
625
+ malformed_object_id="this_id_is_not_valid" &&
626
+
627
+ test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
628
+ remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id
629
+ EOF
630
+ test_grep "not a valid object name '$malformed_object_id'" err
631
+ )
632
+'
633
+
634
+test_expect_success 'remote-object-info fails on malformed OID with default filter' '
635
+ (
636
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
637
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
638
+ malformed_object_id="this_id_is_not_valid" &&
639
+
640
+ test_must_fail git cat-file --batch-command 2>err <<-EOF &&
641
+ remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id
642
+ EOF
643
+ test_grep "not a valid object name '$malformed_object_id'" err
644
+ )
645
+'
646
+
647
+test_expect_success 'remote-object-info fails on not providing OID' '
648
+ (
649
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
650
+ cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
651
+
652
+ test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
653
+ remote-object-info "$HTTPD_URL/smart/http_parent"
654
+ EOF
655
+ test_grep "remote-object-info requires objects" err
656
+ )
657
+'
658
+
659
+
660
+# Test --batch-command remote-object-info with 'http://' transport and
661
+# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
662
+test_expect_success 'batch-command remote-object-info http:// fails when transfer.advertiseobjectinfo=false ' '
663
+ (
664
+ set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
665
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo false &&
666
+
667
+ test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
668
+ remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid
669
+ EOF
670
+ test_grep "object-info capability is not enabled on the server" err &&
671
+
672
+ # revert server state back
673
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true
674
+ )
675
+'
676
+
677
+# DO NOT add non-httpd-specific tests here, because the last part of this
678
+# test script is only executed when httpd is available and enabled.
679
+
680
+test_done