Skip to content

Commit 1077d81

Browse files
committed
Merge branch 'dl/test-must-fail-fixes-5' into pu
The effort to avoid using test_must_fail on non-git command continues. * dl/test-must-fail-fixes-5: lib-submodule-update: use callbacks in test_submodule_switch_common() lib-submodule-update: prepend "git" to $command lib-submodule-update: consolidate --recurse-submodules lib-submodule-update: add space after function name
2 parents ff6cf31 + 7f330ea commit 1077d81

13 files changed

+132
-99
lines changed

t/lib-submodule-update.sh

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test_git_directory_is_unchanged () {
183183
)
184184
}
185185

186-
test_git_directory_exists() {
186+
test_git_directory_exists () {
187187
test -e ".git/modules/$1" &&
188188
if test -f sub1/.git
189189
then
@@ -307,10 +307,23 @@ test_submodule_content () {
307307
# to protect the history!
308308
#
309309

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+
314327
######################### Appearing submodule #########################
315328
# Switching to a commit letting a submodule appear creates empty dir ...
316329
if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1
@@ -326,7 +339,10 @@ test_submodule_switch_common() {
326339
(
327340
cd submodule_update &&
328341
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" &&
330346
test_superproject_content origin/add_sub1 &&
331347
test_dir_is_empty sub1 &&
332348
git submodule update --init --recursive &&
@@ -341,7 +357,10 @@ test_submodule_switch_common() {
341357
cd submodule_update &&
342358
mkdir sub1 &&
343359
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" &&
345364
test_superproject_content origin/add_sub1 &&
346365
test_dir_is_empty sub1 &&
347366
git submodule update --init --recursive &&
@@ -356,7 +375,10 @@ test_submodule_switch_common() {
356375
(
357376
cd submodule_update &&
358377
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" &&
360382
test_superproject_content origin/replace_file_with_sub1 &&
361383
test_dir_is_empty sub1 &&
362384
git submodule update --init --recursive &&
@@ -380,7 +402,10 @@ test_submodule_switch_common() {
380402
(
381403
cd submodule_update &&
382404
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" &&
384409
test_superproject_content origin/replace_directory_with_sub1 &&
385410
test_dir_is_empty sub1 &&
386411
git submodule update --init --recursive &&
@@ -402,7 +427,10 @@ test_submodule_switch_common() {
402427
(
403428
cd submodule_update &&
404429
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" &&
406434
test_superproject_content origin/remove_sub1 &&
407435
test_submodule_content sub1 origin/add_sub1
408436
)
@@ -415,7 +443,10 @@ test_submodule_switch_common() {
415443
cd submodule_update &&
416444
git branch -t remove_sub1 origin/remove_sub1 &&
417445
replace_gitfile_with_git_dir sub1 &&
418-
$command remove_sub1 &&
446+
arg=remove_sub1 &&
447+
$before "$arg" &&
448+
eval $command &&
449+
$after "$arg" &&
419450
test_superproject_content origin/remove_sub1 &&
420451
test_git_directory_is_unchanged sub1 &&
421452
test_submodule_content sub1 origin/add_sub1
@@ -443,7 +474,9 @@ test_submodule_switch_common() {
443474
(
444475
cd submodule_update &&
445476
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 &&
447480
test_superproject_content origin/add_sub1 &&
448481
test_submodule_content sub1 origin/add_sub1
449482
)
@@ -456,7 +489,9 @@ test_submodule_switch_common() {
456489
cd submodule_update &&
457490
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
458491
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 &&
460495
test_superproject_content origin/add_sub1 &&
461496
test_git_directory_is_unchanged sub1 &&
462497
test_submodule_content sub1 origin/add_sub1
@@ -470,7 +505,9 @@ test_submodule_switch_common() {
470505
(
471506
cd submodule_update &&
472507
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 &&
474511
test_superproject_content origin/add_sub1 &&
475512
test_submodule_content sub1 origin/add_sub1
476513
)
@@ -484,7 +521,9 @@ test_submodule_switch_common() {
484521
cd submodule_update &&
485522
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
486523
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 &&
488527
test_superproject_content origin/add_sub1 &&
489528
test_git_directory_is_unchanged sub1 &&
490529
test_submodule_content sub1 origin/add_sub1
@@ -508,7 +547,10 @@ test_submodule_switch_common() {
508547
(
509548
cd submodule_update &&
510549
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" &&
512554
test_superproject_content origin/modify_sub1 &&
513555
test_submodule_content sub1 origin/add_sub1 &&
514556
git submodule update &&
@@ -523,7 +565,10 @@ test_submodule_switch_common() {
523565
(
524566
cd submodule_update &&
525567
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" &&
527572
test_superproject_content origin/invalid_sub1 &&
528573
test_submodule_content sub1 origin/add_sub1 &&
529574
test_must_fail git submodule update &&
@@ -538,7 +583,10 @@ test_submodule_switch_common() {
538583
(
539584
cd submodule_update &&
540585
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" &&
542590
test_superproject_content origin/valid_sub1 &&
543591
test_dir_is_empty sub1 &&
544592
git submodule update --init --recursive &&
@@ -566,10 +614,12 @@ test_submodule_switch_common() {
566614
# # Do something here that updates the worktree and index to match target,
567615
# # but not any submodule directories.
568616
# }
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"
573623

574624
# An empty directory does not prevent the creation of a submodule of
575625
# the same name, but a file does.
@@ -580,17 +630,23 @@ test_submodule_switch () {
580630
cd submodule_update &&
581631
git branch -t add_sub1 origin/add_sub1 &&
582632
>sub1 &&
583-
test_must_fail $command add_sub1 &&
633+
arg=add_sub1 &&
634+
$before "$arg" &&
635+
eval test_must_fail $command &&
584636
test_superproject_content origin/no_submodule &&
585637
test_must_be_empty sub1
586638
)
587639
'
588640
}
589641

642+
test_submodule_switch () {
643+
test_submodule_switch_func "$1 \$arg"
644+
}
645+
590646
# Same as test_submodule_switch(), except that throwing away local changes in
591647
# the superproject is allowed.
592648
test_submodule_forced_switch () {
593-
command="$1"
649+
command="git $1 \$arg"
594650
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
595651
test_submodule_switch_common "$command"
596652

@@ -603,7 +659,8 @@ test_submodule_forced_switch () {
603659
cd submodule_update &&
604660
git branch -t add_sub1 origin/add_sub1 &&
605661
>sub1 &&
606-
$command add_sub1 &&
662+
arg=add_sub1 &&
663+
eval $command &&
607664
test_superproject_content origin/add_sub1 &&
608665
test_dir_is_empty sub1
609666
)
@@ -631,8 +688,8 @@ test_submodule_forced_switch () {
631688

632689
# Internal function; use test_submodule_switch_recursing_with_args() or
633690
# 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"
636693

637694
######################### Appearing submodule #########################
638695
# Switching to a commit letting a submodule appear checks it out ...
@@ -840,7 +897,7 @@ test_submodule_recursing_with_args_common() {
840897
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
841898
test_submodule_switch_recursing_with_args () {
842899
cmd_args="$1"
843-
command="git $cmd_args --recurse-submodules"
900+
command="git $cmd_args"
844901
test_submodule_recursing_with_args_common "$command"
845902

846903
RESULTDS=success
@@ -957,7 +1014,7 @@ test_submodule_switch_recursing_with_args () {
9571014
# away local changes in the superproject is allowed.
9581015
test_submodule_forced_switch_recursing_with_args () {
9591016
cmd_args="$1"
960-
command="git $cmd_args --recurse-submodules"
1017+
command="git $cmd_args"
9611018
test_submodule_recursing_with_args_common "$command"
9621019

9631020
RESULT=success

t/t1013-read-tree-submodule.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ test_submodule_switch_recursing_with_args "read-tree -u -m"
1212

1313
test_submodule_forced_switch_recursing_with_args "read-tree -u --reset"
1414

15-
test_submodule_switch "git read-tree -u -m"
15+
test_submodule_switch "read-tree -u -m"
1616

17-
test_submodule_forced_switch "git read-tree -u --reset"
17+
test_submodule_forced_switch "read-tree -u --reset"
1818

1919
test_done

t/t2013-checkout-submodule.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ test_submodule_switch_recursing_with_args "checkout"
6868

6969
test_submodule_forced_switch_recursing_with_args "checkout -f"
7070

71-
test_submodule_switch "git checkout"
71+
test_submodule_switch "checkout"
7272

73-
test_submodule_forced_switch "git checkout -f"
73+
test_submodule_forced_switch "checkout -f"
7474

7575
test_done

t/t3426-rebase-submodule.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ git_rebase () {
1616
git revert HEAD &&
1717
git status -su >actual &&
1818
ls -1pR * >>actual &&
19-
test_cmp expect actual &&
20-
git rebase "$1"
19+
test_cmp expect actual
2120
}
2221

23-
test_submodule_switch "git_rebase"
22+
test_submodule_switch_func "rebase \$arg" "git_rebase"
2423

2524
git_rebase_interactive () {
2625
git status -su >expect &&
@@ -34,11 +33,10 @@ git_rebase_interactive () {
3433
ls -1pR * >>actual &&
3534
test_cmp expect actual &&
3635
set_fake_editor &&
37-
echo "fake-editor.sh" >.git/info/exclude &&
38-
git rebase -i "$1"
36+
echo "fake-editor.sh" >.git/info/exclude
3937
}
4038

41-
test_submodule_switch "git_rebase_interactive"
39+
test_submodule_switch_func "rebase -i \$arg" "git_rebase_interactive"
4240

4341
test_expect_success 'rebase interactive ignores modified submodules' '
4442
test_when_finished "rm -rf super sub" &&

t/t3512-cherry-pick-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test_description='cherry-pick can handle submodules'
77

88
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
99
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
10-
test_submodule_switch "git cherry-pick"
10+
test_submodule_switch "cherry-pick"
1111

1212
test_expect_success 'unrelated submodule/file conflict is ignored' '
1313
test_create_repo sub &&

t/t3513-revert-submodule.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ test_description='revert can handle submodules'
1111
# first so we can restore the work tree test setup after doing the checkout
1212
# and revert. We test here that the restored work tree content is identical
1313
# to that at the beginning. The last revert is then tested by the framework.
14-
git_revert () {
14+
git_revert_before () {
1515
git status -su >expect &&
1616
ls -1pR * >>expect &&
17-
tar cf "$TRASH_DIRECTORY/tmp.tar" * &&
18-
git checkout "$1" &&
17+
tar cf "$TRASH_DIRECTORY/tmp.tar" *
18+
}
19+
20+
git_revert_after () {
1921
git revert HEAD &&
2022
rm -rf * &&
2123
tar xf "$TRASH_DIRECTORY/tmp.tar" &&
@@ -26,6 +28,6 @@ git_revert () {
2628
}
2729

2830
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
29-
test_submodule_switch "git_revert"
31+
test_submodule_switch_func "checkout \$arg" "git_revert_before" "git_revert_after"
3032

3133
test_done

t/t3906-stash-submodule.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ test_description='stash can handle submodules'
55
. ./test-lib.sh
66
. "$TEST_DIRECTORY"/lib-submodule-update.sh
77

8-
git_stash () {
8+
git_stash_before () {
99
git status -su >expect &&
10-
ls -1pR * >>expect &&
11-
git read-tree -u -m "$1" &&
10+
ls -1pR * >>expect
11+
}
12+
13+
git_stash_after () {
1214
git stash &&
1315
git status -su >actual &&
1416
ls -1pR * >>actual &&
@@ -19,7 +21,7 @@ git_stash () {
1921
KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
2022
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
2123
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
22-
test_submodule_switch "git_stash"
24+
test_submodule_switch_func "read-tree -u -m \$arg" "git_stash_before" "git_stash_after"
2325

2426
setup_basic () {
2527
test_when_finished "rm -rf main sub" &&

0 commit comments

Comments
 (0)