@@ -183,7 +183,7 @@ test_git_directory_is_unchanged () {
183
183
)
184
184
}
185
185
186
- test_git_directory_exists () {
186
+ test_git_directory_exists () {
187
187
test -e " .git/modules/$1 " &&
188
188
if test -f sub1/.git
189
189
then
@@ -307,10 +307,23 @@ test_submodule_content () {
307
307
# to protect the history!
308
308
#
309
309
310
- # Internal function; use test_submodule_switch() or
311
- # test_submodule_forced_switch() instead.
312
- test_submodule_switch_common () {
313
- command=" $1 "
310
+ # Internal function; use test_submodule_switch_func(), test_submodule_switch(),
311
+ # or test_submodule_forced_switch() instead.
312
+ test_submodule_switch_common () {
313
+ command=" $1 " # should be a git command
314
+ before=" $2 "
315
+ after=" $3 "
316
+
317
+ if test -z " $before "
318
+ then
319
+ before=true
320
+ fi
321
+
322
+ if test -z " $after "
323
+ then
324
+ after=true
325
+ fi
326
+
314
327
# ######################## Appearing submodule #########################
315
328
# Switching to a commit letting a submodule appear creates empty dir ...
316
329
if test " $KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES " = 1
@@ -326,7 +339,10 @@ test_submodule_switch_common() {
326
339
(
327
340
cd submodule_update &&
328
341
git branch -t add_sub1 origin/add_sub1 &&
329
- $command add_sub1 &&
342
+ arg=add_sub1 &&
343
+ $before "$arg" &&
344
+ eval $command &&
345
+ $after "$arg" &&
330
346
test_superproject_content origin/add_sub1 &&
331
347
test_dir_is_empty sub1 &&
332
348
git submodule update --init --recursive &&
@@ -341,7 +357,10 @@ test_submodule_switch_common() {
341
357
cd submodule_update &&
342
358
mkdir sub1 &&
343
359
git branch -t add_sub1 origin/add_sub1 &&
344
- $command add_sub1 &&
360
+ arg=add_sub1 &&
361
+ $before "$arg" &&
362
+ eval $command &&
363
+ $after "$arg" &&
345
364
test_superproject_content origin/add_sub1 &&
346
365
test_dir_is_empty sub1 &&
347
366
git submodule update --init --recursive &&
@@ -356,7 +375,10 @@ test_submodule_switch_common() {
356
375
(
357
376
cd submodule_update &&
358
377
git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 &&
359
- $command replace_file_with_sub1 &&
378
+ arg=replace_file_with_sub1 &&
379
+ $before "$arg" &&
380
+ eval $command &&
381
+ $after "$arg" &&
360
382
test_superproject_content origin/replace_file_with_sub1 &&
361
383
test_dir_is_empty sub1 &&
362
384
git submodule update --init --recursive &&
@@ -380,7 +402,10 @@ test_submodule_switch_common() {
380
402
(
381
403
cd submodule_update &&
382
404
git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 &&
383
- $command replace_directory_with_sub1 &&
405
+ arg=replace_directory_with_sub1 &&
406
+ $before "$arg" &&
407
+ eval $command &&
408
+ $after "$arg" &&
384
409
test_superproject_content origin/replace_directory_with_sub1 &&
385
410
test_dir_is_empty sub1 &&
386
411
git submodule update --init --recursive &&
@@ -402,7 +427,10 @@ test_submodule_switch_common() {
402
427
(
403
428
cd submodule_update &&
404
429
git branch -t remove_sub1 origin/remove_sub1 &&
405
- $command remove_sub1 &&
430
+ arg=remove_sub1 &&
431
+ $before "$arg" &&
432
+ eval $command &&
433
+ $after "$arg" &&
406
434
test_superproject_content origin/remove_sub1 &&
407
435
test_submodule_content sub1 origin/add_sub1
408
436
)
@@ -415,7 +443,10 @@ test_submodule_switch_common() {
415
443
cd submodule_update &&
416
444
git branch -t remove_sub1 origin/remove_sub1 &&
417
445
replace_gitfile_with_git_dir sub1 &&
418
- $command remove_sub1 &&
446
+ arg=remove_sub1 &&
447
+ $before "$arg" &&
448
+ eval $command &&
449
+ $after "$arg" &&
419
450
test_superproject_content origin/remove_sub1 &&
420
451
test_git_directory_is_unchanged sub1 &&
421
452
test_submodule_content sub1 origin/add_sub1
@@ -443,7 +474,9 @@ test_submodule_switch_common() {
443
474
(
444
475
cd submodule_update &&
445
476
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
446
- test_must_fail $command replace_sub1_with_directory &&
477
+ arg=replace_sub1_with_directory &&
478
+ $before "$arg" &&
479
+ eval test_must_fail $command &&
447
480
test_superproject_content origin/add_sub1 &&
448
481
test_submodule_content sub1 origin/add_sub1
449
482
)
@@ -456,7 +489,9 @@ test_submodule_switch_common() {
456
489
cd submodule_update &&
457
490
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
458
491
replace_gitfile_with_git_dir sub1 &&
459
- test_must_fail $command replace_sub1_with_directory &&
492
+ arg=replace_sub1_with_directory &&
493
+ $before "$arg" &&
494
+ eval test_must_fail $command &&
460
495
test_superproject_content origin/add_sub1 &&
461
496
test_git_directory_is_unchanged sub1 &&
462
497
test_submodule_content sub1 origin/add_sub1
@@ -470,7 +505,9 @@ test_submodule_switch_common() {
470
505
(
471
506
cd submodule_update &&
472
507
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
473
- test_must_fail $command replace_sub1_with_file &&
508
+ arg=replace_sub1_with_file &&
509
+ $before "$arg" &&
510
+ eval test_must_fail $command &&
474
511
test_superproject_content origin/add_sub1 &&
475
512
test_submodule_content sub1 origin/add_sub1
476
513
)
@@ -484,7 +521,9 @@ test_submodule_switch_common() {
484
521
cd submodule_update &&
485
522
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
486
523
replace_gitfile_with_git_dir sub1 &&
487
- test_must_fail $command replace_sub1_with_file &&
524
+ arg=replace_sub1_with_file &&
525
+ $before "$arg" &&
526
+ eval test_must_fail $command &&
488
527
test_superproject_content origin/add_sub1 &&
489
528
test_git_directory_is_unchanged sub1 &&
490
529
test_submodule_content sub1 origin/add_sub1
@@ -508,7 +547,10 @@ test_submodule_switch_common() {
508
547
(
509
548
cd submodule_update &&
510
549
git branch -t modify_sub1 origin/modify_sub1 &&
511
- $command modify_sub1 &&
550
+ arg=modify_sub1 &&
551
+ $before "$arg" &&
552
+ eval $command &&
553
+ $after "$arg" &&
512
554
test_superproject_content origin/modify_sub1 &&
513
555
test_submodule_content sub1 origin/add_sub1 &&
514
556
git submodule update &&
@@ -523,7 +565,10 @@ test_submodule_switch_common() {
523
565
(
524
566
cd submodule_update &&
525
567
git branch -t invalid_sub1 origin/invalid_sub1 &&
526
- $command invalid_sub1 &&
568
+ arg=invalid_sub1 &&
569
+ $before "$arg" &&
570
+ eval $command &&
571
+ $after "$arg" &&
527
572
test_superproject_content origin/invalid_sub1 &&
528
573
test_submodule_content sub1 origin/add_sub1 &&
529
574
test_must_fail git submodule update &&
@@ -538,7 +583,10 @@ test_submodule_switch_common() {
538
583
(
539
584
cd submodule_update &&
540
585
git branch -t valid_sub1 origin/valid_sub1 &&
541
- $command valid_sub1 &&
586
+ arg=valid_sub1 &&
587
+ $before "$arg" &&
588
+ eval $command &&
589
+ $after "$arg" &&
542
590
test_superproject_content origin/valid_sub1 &&
543
591
test_dir_is_empty sub1 &&
544
592
git submodule update --init --recursive &&
@@ -566,10 +614,12 @@ test_submodule_switch_common() {
566
614
# # Do something here that updates the worktree and index to match target,
567
615
# # but not any submodule directories.
568
616
# }
569
- # test_submodule_switch "my_func"
570
- test_submodule_switch () {
571
- command=" $1 "
572
- test_submodule_switch_common " $command "
617
+ # test_submodule_switch_func "my_func"
618
+ test_submodule_switch_func () {
619
+ command=" git $1 "
620
+ before=" $2 "
621
+ after=" $3 "
622
+ test_submodule_switch_common " $command " " $before " " $after "
573
623
574
624
# An empty directory does not prevent the creation of a submodule of
575
625
# the same name, but a file does.
@@ -580,17 +630,23 @@ test_submodule_switch () {
580
630
cd submodule_update &&
581
631
git branch -t add_sub1 origin/add_sub1 &&
582
632
>sub1 &&
583
- test_must_fail $command add_sub1 &&
633
+ arg=add_sub1 &&
634
+ $before "$arg" &&
635
+ eval test_must_fail $command &&
584
636
test_superproject_content origin/no_submodule &&
585
637
test_must_be_empty sub1
586
638
)
587
639
'
588
640
}
589
641
642
+ test_submodule_switch () {
643
+ test_submodule_switch_func " $1 \$ arg"
644
+ }
645
+
590
646
# Same as test_submodule_switch(), except that throwing away local changes in
591
647
# the superproject is allowed.
592
648
test_submodule_forced_switch () {
593
- command=" $1 "
649
+ command=" git $1 \$ arg "
594
650
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
595
651
test_submodule_switch_common " $command "
596
652
@@ -603,7 +659,8 @@ test_submodule_forced_switch () {
603
659
cd submodule_update &&
604
660
git branch -t add_sub1 origin/add_sub1 &&
605
661
>sub1 &&
606
- $command add_sub1 &&
662
+ arg=add_sub1 &&
663
+ eval $command &&
607
664
test_superproject_content origin/add_sub1 &&
608
665
test_dir_is_empty sub1
609
666
)
@@ -631,8 +688,8 @@ test_submodule_forced_switch () {
631
688
632
689
# Internal function; use test_submodule_switch_recursing_with_args() or
633
690
# test_submodule_forced_switch_recursing_with_args() instead.
634
- test_submodule_recursing_with_args_common () {
635
- command=" $1 "
691
+ test_submodule_recursing_with_args_common () {
692
+ command=" $1 --recurse-submodules "
636
693
637
694
# ######################## Appearing submodule #########################
638
695
# Switching to a commit letting a submodule appear checks it out ...
@@ -840,7 +897,7 @@ test_submodule_recursing_with_args_common() {
840
897
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
841
898
test_submodule_switch_recursing_with_args () {
842
899
cmd_args=" $1 "
843
- command=" git $cmd_args --recurse-submodules "
900
+ command=" git $cmd_args "
844
901
test_submodule_recursing_with_args_common " $command "
845
902
846
903
RESULTDS=success
@@ -957,7 +1014,7 @@ test_submodule_switch_recursing_with_args () {
957
1014
# away local changes in the superproject is allowed.
958
1015
test_submodule_forced_switch_recursing_with_args () {
959
1016
cmd_args=" $1 "
960
- command=" git $cmd_args --recurse-submodules "
1017
+ command=" git $cmd_args "
961
1018
test_submodule_recursing_with_args_common " $command "
962
1019
963
1020
RESULT=success
0 commit comments