@@ -185,6 +185,43 @@ test_expect_success 'server-options are sent when using ls-remote' '
185
185
grep "server-option=world" log
186
186
'
187
187
188
+ test_expect_success ' server-options from configuration are used by ls-remote' '
189
+ test_when_finished "rm -rf log myclone" &&
190
+ git clone "file://$(pwd)/file_parent" myclone &&
191
+ cat >expect <<-EOF &&
192
+ $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
193
+ EOF
194
+
195
+ # Default server options from configuration are used
196
+ git -C myclone config --add remote.origin.serverOption foo &&
197
+ git -C myclone config --add remote.origin.serverOption bar &&
198
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
199
+ ls-remote origin main >actual &&
200
+ test_cmp expect actual &&
201
+ test_grep "ls-remote> server-option=foo" log &&
202
+ test_grep "ls-remote> server-option=bar" log &&
203
+ rm -f log &&
204
+
205
+ # Empty value of remote.<name>.serverOption clears the list
206
+ git -C myclone config --add remote.origin.serverOption "" &&
207
+ git -C myclone config --add remote.origin.serverOption tar &&
208
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
209
+ ls-remote origin main >actual &&
210
+ test_cmp expect actual &&
211
+ test_grep "ls-remote> server-option=tar" log &&
212
+ test_grep ! "ls-remote> server-option=foo" log &&
213
+ test_grep ! "ls-remote> server-option=bar" log &&
214
+ rm -f log &&
215
+
216
+ # Server option from command line overrides those from configuration
217
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
218
+ ls-remote -o hello -o world origin main >actual &&
219
+ test_cmp expect actual &&
220
+ test_grep "ls-remote> server-option=hello" log &&
221
+ test_grep "ls-remote> server-option=world" log &&
222
+ test_grep ! "ls-remote> server-option=tar" log
223
+ '
224
+
188
225
test_expect_success ' warn if using server-option with ls-remote with legacy protocol' '
189
226
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
190
227
ls-remote -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
@@ -381,6 +418,54 @@ test_expect_success 'server-options are sent when fetching' '
381
418
grep "server-option=world" log
382
419
'
383
420
421
+ test_expect_success ' server-options are sent when fetch multiple remotes' '
422
+ test_when_finished "rm -f log server_options_sent" &&
423
+ git clone "file://$(pwd)/file_parent" child_multi_remotes &&
424
+ git -C child_multi_remotes remote add another "file://$(pwd)/file_parent" &&
425
+ GIT_TRACE_PACKET="$(pwd)/log" git -C child_multi_remotes -c protocol.version=2 \
426
+ fetch -o hello --all &&
427
+ grep "fetch> server-option=hello" log >server_options_sent &&
428
+ test_line_count = 2 server_options_sent
429
+ '
430
+
431
+ test_expect_success ' server-options from configuration are used by git-fetch' '
432
+ test_when_finished "rm -rf log myclone" &&
433
+ git clone "file://$(pwd)/file_parent" myclone &&
434
+ git -C file_parent log -1 --format=%s >expect &&
435
+
436
+ # Default server options from configuration are used
437
+ git -C myclone config --add remote.origin.serverOption foo &&
438
+ git -C myclone config --add remote.origin.serverOption bar &&
439
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
440
+ fetch origin main &&
441
+ git -C myclone log -1 --format=%s origin/main >actual &&
442
+ test_cmp expect actual &&
443
+ test_grep "fetch> server-option=foo" log &&
444
+ test_grep "fetch> server-option=bar" log &&
445
+ rm -f log &&
446
+
447
+ # Empty value of remote.<name>.serverOption clears the list
448
+ git -C myclone config --add remote.origin.serverOption "" &&
449
+ git -C myclone config --add remote.origin.serverOption tar &&
450
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
451
+ fetch origin main &&
452
+ git -C myclone log -1 --format=%s origin/main >actual &&
453
+ test_cmp expect actual &&
454
+ test_grep "fetch> server-option=tar" log &&
455
+ test_grep ! "fetch> server-option=foo" log &&
456
+ test_grep ! "fetch> server-option=bar" log &&
457
+ rm -f log &&
458
+
459
+ # Server option from command line overrides those from configuration
460
+ GIT_TRACE_PACKET="$(pwd)/log" git -C myclone -c protocol.version=2 \
461
+ fetch -o hello -o world origin main &&
462
+ git -C myclone log -1 --format=%s origin/main >actual &&
463
+ test_cmp expect actual &&
464
+ test_grep "fetch> server-option=hello" log &&
465
+ test_grep "fetch> server-option=world" log &&
466
+ test_grep ! "fetch> server-option=tar" log
467
+ '
468
+
384
469
test_expect_success ' warn if using server-option with fetch with legacy protocol' '
385
470
test_when_finished "rm -rf temp_child" &&
386
471
@@ -404,6 +489,37 @@ test_expect_success 'server-options are sent when cloning' '
404
489
grep "server-option=world" log
405
490
'
406
491
492
+ test_expect_success ' server-options from configuration are used by git-clone' '
493
+ test_when_finished "rm -rf log myclone" &&
494
+
495
+ # Default server options from configuration are used
496
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
497
+ -c remote.origin.serverOption=foo -c remote.origin.serverOption=bar \
498
+ clone "file://$(pwd)/file_parent" myclone &&
499
+ test_grep "clone> server-option=foo" log &&
500
+ test_grep "clone> server-option=bar" log &&
501
+ rm -rf log myclone &&
502
+
503
+ # Empty value of remote.<name>.serverOption clears the list
504
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
505
+ -c remote.origin.serverOption=foo -c remote.origin.serverOption=bar \
506
+ -c remote.origin.serverOption= -c remote.origin.serverOption=tar \
507
+ clone "file://$(pwd)/file_parent" myclone &&
508
+ test_grep "clone> server-option=tar" log &&
509
+ test_grep ! "clone> server-option=foo" log &&
510
+ test_grep ! "clone> server-option=bar" log &&
511
+ rm -rf log myclone &&
512
+
513
+ # Server option from command line overrides those from configuration
514
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
515
+ -c remote.origin.serverOption=tar \
516
+ clone --server-option=hello --server-option=world \
517
+ "file://$(pwd)/file_parent" myclone &&
518
+ test_grep "clone> server-option=hello" log &&
519
+ test_grep "clone> server-option=world" log &&
520
+ test_grep ! "clone> server-option=tar" log
521
+ '
522
+
407
523
test_expect_success ' warn if using server-option with clone with legacy protocol' '
408
524
test_when_finished "rm -rf myclone" &&
409
525
@@ -415,6 +531,23 @@ test_expect_success 'warn if using server-option with clone with legacy protocol
415
531
test_grep "server options require protocol version 2 or later" err
416
532
'
417
533
534
+ test_expect_success ' server-option configuration with legacy protocol is ok' '
535
+ test_when_finished "rm -rf myclone" &&
536
+
537
+ env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
538
+ -c remote.origin.serverOption=foo -c remote.origin.serverOption=bar \
539
+ clone "file://$(pwd)/file_parent" myclone
540
+ '
541
+
542
+ test_expect_success ' invalid server-option configuration' '
543
+ test_when_finished "rm -rf myclone" &&
544
+
545
+ test_must_fail git -c protocol.version=2 \
546
+ -c remote.origin.serverOption \
547
+ clone "file://$(pwd)/file_parent" myclone 2>err &&
548
+ test_grep "error: missing value for ' \' ' remote.origin.serveroption' \' ' " err
549
+ '
550
+
418
551
test_expect_success ' upload-pack respects config using protocol v2' '
419
552
git init server &&
420
553
write_script server/.git/hook <<-\EOF &&
0 commit comments