303
# update" is run. And even then that command doesn't delete the work tree of
304
# a removed submodule.
305
#
306
+# The first argument of the callback function will be the name of the submodule.
307
+#
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.
312
#
313
314
# Internal function; use test_submodule_switch_func(), test_submodule_switch(),
447
(
448
cd submodule_update &&
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 &&
451
test_superproject_content origin/add_sub1 &&
452
test_submodule_content sub1 origin/add_sub1
453
)
460
cd submodule_update &&
461
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
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 &&
464
test_superproject_content origin/add_sub1 &&
465
test_git_directory_is_unchanged sub1 &&
466
test_submodule_content sub1 origin/add_sub1
474
(
475
cd submodule_update &&
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 &&
478
test_superproject_content origin/add_sub1 &&
479
test_submodule_content sub1 origin/add_sub1
480
)
488
cd submodule_update &&
489
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
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 &&
492
test_superproject_content origin/add_sub1 &&
493
test_git_directory_is_unchanged sub1 &&
494
test_submodule_content sub1 origin/add_sub1
563
# conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests
564
# below to 1.
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.
576
#
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...
585
# }
586
# test_submodule_switch_func "my_func"
587
test_submodule_switch_func () {
597
cd submodule_update &&
598
git branch -t add_sub1 origin/add_sub1 &&
599
>sub1 &&
583
- test_must_fail $command add_sub1 &&
600
+ $command add_sub1 test_must_fail &&
601
test_superproject_content origin/no_submodule &&
602
test_must_be_empty sub1
603
)
604
'
605
}
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 () {
591
- test_submodule_switch_func "git $1"
618
+ gitcmd="$1"
619
+ test_submodule_switch_func "git_test_func"
620
}
621
622
# Same as test_submodule_switch(), except that throwing away local changes in
623
# the superproject is allowed.
624
test_submodule_forced_switch () {
597
- command="$1"
625
+ gitcmd="$1"
626
+ command="git_test_func"
627
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
599
- test_submodule_switch_common "git $command"
628
+ test_submodule_switch_common "$command"
629
630
# When forced, a file in the superproject does not prevent creating a
631
# submodule of the same name.