@@ -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
@@ -303,13 +303,17 @@ test_submodule_content () {
303
303
# update" is run. And even then that command doesn't delete the work tree of
304
304
# a removed submodule.
305
305
#
306
+ # The first argument of the callback function will be the name of the submodule.
307
+ #
306
308
# Removing a submodule containing a .git directory must fail even when forced
307
- # to protect the history!
309
+ # to protect the history! If we are testing this case, the second argument of
310
+ # the callback function will be 'test_must_fail', else it will be the empty
311
+ # string.
308
312
#
309
313
310
- # Internal function; use test_submodule_switch() or
311
- # test_submodule_forced_switch() instead.
312
- test_submodule_switch_common () {
314
+ # Internal function; use test_submodule_switch_func(), test_submodule_switch(),
315
+ # or test_submodule_forced_switch() instead.
316
+ test_submodule_switch_common () {
313
317
command=" $1 "
314
318
# ######################## Appearing submodule #########################
315
319
# Switching to a commit letting a submodule appear creates empty dir ...
@@ -443,7 +447,7 @@ test_submodule_switch_common() {
443
447
(
444
448
cd submodule_update &&
445
449
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
446
- test_must_fail $command replace_sub1_with_directory &&
450
+ $command replace_sub1_with_directory test_must_fail &&
447
451
test_superproject_content origin/add_sub1 &&
448
452
test_submodule_content sub1 origin/add_sub1
449
453
)
@@ -456,7 +460,7 @@ test_submodule_switch_common() {
456
460
cd submodule_update &&
457
461
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
458
462
replace_gitfile_with_git_dir sub1 &&
459
- test_must_fail $command replace_sub1_with_directory &&
463
+ $command replace_sub1_with_directory test_must_fail &&
460
464
test_superproject_content origin/add_sub1 &&
461
465
test_git_directory_is_unchanged sub1 &&
462
466
test_submodule_content sub1 origin/add_sub1
@@ -470,7 +474,7 @@ test_submodule_switch_common() {
470
474
(
471
475
cd submodule_update &&
472
476
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
473
- test_must_fail $command replace_sub1_with_file &&
477
+ $command replace_sub1_with_file test_must_fail &&
474
478
test_superproject_content origin/add_sub1 &&
475
479
test_submodule_content sub1 origin/add_sub1
476
480
)
@@ -484,7 +488,7 @@ test_submodule_switch_common() {
484
488
cd submodule_update &&
485
489
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
486
490
replace_gitfile_with_git_dir sub1 &&
487
- test_must_fail $command replace_sub1_with_file &&
491
+ $command replace_sub1_with_file test_must_fail &&
488
492
test_superproject_content origin/add_sub1 &&
489
493
test_git_directory_is_unchanged sub1 &&
490
494
test_submodule_content sub1 origin/add_sub1
@@ -559,15 +563,28 @@ test_submodule_switch_common() {
559
563
# conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests
560
564
# below to 1.
561
565
#
562
- # Use as follows:
566
+ # The first argument of the callback function will be the name of the submodule.
567
+ #
568
+ # Removing a submodule containing a .git directory must fail even when forced
569
+ # to protect the history! If we are testing this case, the second argument of
570
+ # the callback function will be 'test_must_fail', else it will be the empty
571
+ # string.
572
+ #
573
+ # The following example uses `git some-command` as an example command to be
574
+ # tested. It updates the worktree and index to match a target, but not any
575
+ # submodule directories.
563
576
#
564
577
# my_func () {
565
- # target=$1
566
- # # Do something here that updates the worktree and index to match target,
567
- # # but not any submodule directories.
578
+ # ...prepare for `git some-command` to be run...
579
+ # $2 git some-command "$1" &&
580
+ # if test -n "$2"
581
+ # then
582
+ # return
583
+ # fi &&
584
+ # ...check the state after git some-command is run...
568
585
# }
569
- # test_submodule_switch "my_func"
570
- test_submodule_switch () {
586
+ # test_submodule_switch_func "my_func"
587
+ test_submodule_switch_func () {
571
588
command=" $1 "
572
589
test_submodule_switch_common " $command "
573
590
@@ -580,17 +597,33 @@ test_submodule_switch () {
580
597
cd submodule_update &&
581
598
git branch -t add_sub1 origin/add_sub1 &&
582
599
>sub1 &&
583
- test_must_fail $command add_sub1 &&
600
+ $command add_sub1 test_must_fail &&
584
601
test_superproject_content origin/no_submodule &&
585
602
test_must_be_empty sub1
586
603
)
587
604
'
588
605
}
589
606
607
+ # Ensures that the that the arg either contains "test_must_fail" or is empty.
608
+ may_only_be_test_must_fail () {
609
+ test -z " $1 " || test " $1 " = test_must_fail || die
610
+ }
611
+
612
+ git_test_func () {
613
+ may_only_be_test_must_fail " $2 " &&
614
+ $2 git $gitcmd " $1 "
615
+ }
616
+
617
+ test_submodule_switch () {
618
+ gitcmd=" $1 "
619
+ test_submodule_switch_func " git_test_func"
620
+ }
621
+
590
622
# Same as test_submodule_switch(), except that throwing away local changes in
591
623
# the superproject is allowed.
592
624
test_submodule_forced_switch () {
593
- command=" $1 "
625
+ gitcmd=" $1 "
626
+ command=" git_test_func"
594
627
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
595
628
test_submodule_switch_common " $command "
596
629
@@ -631,8 +664,8 @@ test_submodule_forced_switch () {
631
664
632
665
# Internal function; use test_submodule_switch_recursing_with_args() or
633
666
# test_submodule_forced_switch_recursing_with_args() instead.
634
- test_submodule_recursing_with_args_common () {
635
- command=" $1 "
667
+ test_submodule_recursing_with_args_common () {
668
+ command=" $1 --recurse-submodules "
636
669
637
670
# ######################## Appearing submodule #########################
638
671
# Switching to a commit letting a submodule appear checks it out ...
@@ -840,7 +873,7 @@ test_submodule_recursing_with_args_common() {
840
873
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
841
874
test_submodule_switch_recursing_with_args () {
842
875
cmd_args=" $1 "
843
- command=" git $cmd_args --recurse-submodules "
876
+ command=" git $cmd_args "
844
877
test_submodule_recursing_with_args_common " $command "
845
878
846
879
RESULTDS=success
@@ -957,7 +990,7 @@ test_submodule_switch_recursing_with_args () {
957
990
# away local changes in the superproject is allowed.
958
991
test_submodule_forced_switch_recursing_with_args () {
959
992
cmd_args=" $1 "
960
- command=" git $cmd_args --recurse-submodules "
993
+ command=" git $cmd_args "
961
994
test_submodule_recursing_with_args_common " $command "
962
995
963
996
RESULT=success
0 commit comments