Skip to content

Commit 3f946f0

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: pass OVERWRITING_FAIL SQUASH??? <20200521112545.GB581643@generichostname> lib-submodule-update: prepend "git" to $command lib-submodule-update: consolidate --recurse-submodules lib-submodule-update: add space after function name
2 parents 53259d8 + e452c3b commit 3f946f0

13 files changed

+92
-54
lines changed

t/lib-submodule-update.sh

Lines changed: 38 additions & 17 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
@@ -304,12 +304,15 @@ test_submodule_content () {
304304
# a removed submodule.
305305
#
306306
# Removing a submodule containing a .git directory must fail even when forced
307-
# to protect the history!
307+
# to protect the history! If we are testing this case,
308+
# OVERWRITING_FAIL=test_must_fail, otherwise OVERWRITING_FAIL will be the empty
309+
# string.
308310
#
309311

310-
# Internal function; use test_submodule_switch() or
311-
# test_submodule_forced_switch() instead.
312-
test_submodule_switch_common() {
312+
# Internal function; use test_submodule_switch_func(), test_submodule_switch(),
313+
# or test_submodule_forced_switch() instead.
314+
test_submodule_switch_common () {
315+
OVERWRITING_FAIL=
313316
command="$1"
314317
######################### Appearing submodule #########################
315318
# Switching to a commit letting a submodule appear creates empty dir ...
@@ -443,7 +446,9 @@ test_submodule_switch_common() {
443446
(
444447
cd submodule_update &&
445448
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
446-
test_must_fail $command replace_sub1_with_directory &&
449+
OVERWRITING_FAIL=test_must_fail &&
450+
$command replace_sub1_with_directory &&
451+
OVERWRITING_FAIL= &&
447452
test_superproject_content origin/add_sub1 &&
448453
test_submodule_content sub1 origin/add_sub1
449454
)
@@ -456,7 +461,9 @@ test_submodule_switch_common() {
456461
cd submodule_update &&
457462
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
458463
replace_gitfile_with_git_dir sub1 &&
459-
test_must_fail $command replace_sub1_with_directory &&
464+
OVERWRITING_FAIL=test_must_fail &&
465+
$command replace_sub1_with_directory &&
466+
OVERWRITING_FAIL= &&
460467
test_superproject_content origin/add_sub1 &&
461468
test_git_directory_is_unchanged sub1 &&
462469
test_submodule_content sub1 origin/add_sub1
@@ -470,7 +477,9 @@ test_submodule_switch_common() {
470477
(
471478
cd submodule_update &&
472479
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
473-
test_must_fail $command replace_sub1_with_file &&
480+
OVERWRITING_FAIL=test_must_fail &&
481+
$command replace_sub1_with_file &&
482+
OVERWRITING_FAIL= &&
474483
test_superproject_content origin/add_sub1 &&
475484
test_submodule_content sub1 origin/add_sub1
476485
)
@@ -484,7 +493,9 @@ test_submodule_switch_common() {
484493
cd submodule_update &&
485494
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
486495
replace_gitfile_with_git_dir sub1 &&
487-
test_must_fail $command replace_sub1_with_file &&
496+
OVERWRITING_FAIL=test_must_fail &&
497+
$command replace_sub1_with_file &&
498+
OVERWRITING_FAIL= &&
488499
test_superproject_content origin/add_sub1 &&
489500
test_git_directory_is_unchanged sub1 &&
490501
test_submodule_content sub1 origin/add_sub1
@@ -559,15 +570,21 @@ test_submodule_switch_common() {
559570
# conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests
560571
# below to 1.
561572
#
573+
# Removing a submodule containing a .git directory must fail even when forced
574+
# to protect the history! If we are testing this case,
575+
# OVERWRITING_FAIL=test_must_fail, otherwise OVERWRITING_FAIL will be the empty
576+
# string.
577+
#
562578
# Use as follows:
563579
#
564580
# my_func () {
565581
# target=$1
566582
# # Do something here that updates the worktree and index to match target,
567583
# # but not any submodule directories.
568584
# }
569-
# test_submodule_switch "my_func"
570-
test_submodule_switch () {
585+
# test_submodule_switch_func "my_func"
586+
test_submodule_switch_func () {
587+
OVERWRITING_FAIL=
571588
command="$1"
572589
test_submodule_switch_common "$command"
573590

@@ -580,19 +597,23 @@ test_submodule_switch () {
580597
cd submodule_update &&
581598
git branch -t add_sub1 origin/add_sub1 &&
582599
>sub1 &&
583-
test_must_fail $command add_sub1 &&
600+
OVERWRITING_FAIL=test_must_fail $command add_sub1 &&
584601
test_superproject_content origin/no_submodule &&
585602
test_must_be_empty sub1
586603
)
587604
'
588605
}
589606

607+
test_submodule_switch () {
608+
test_submodule_switch_func "eval \$OVERWRITING_FAIL git $1"
609+
}
610+
590611
# Same as test_submodule_switch(), except that throwing away local changes in
591612
# the superproject is allowed.
592613
test_submodule_forced_switch () {
593614
command="$1"
594615
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
595-
test_submodule_switch_common "$command"
616+
test_submodule_switch_common "eval \$OVERWRITING_FAIL git $command"
596617

597618
# When forced, a file in the superproject does not prevent creating a
598619
# submodule of the same name.
@@ -631,8 +652,8 @@ test_submodule_forced_switch () {
631652

632653
# Internal function; use test_submodule_switch_recursing_with_args() or
633654
# test_submodule_forced_switch_recursing_with_args() instead.
634-
test_submodule_recursing_with_args_common() {
635-
command="$1"
655+
test_submodule_recursing_with_args_common () {
656+
command="$1 --recurse-submodules"
636657

637658
######################### Appearing submodule #########################
638659
# Switching to a commit letting a submodule appear checks it out ...
@@ -840,7 +861,7 @@ test_submodule_recursing_with_args_common() {
840861
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
841862
test_submodule_switch_recursing_with_args () {
842863
cmd_args="$1"
843-
command="git $cmd_args --recurse-submodules"
864+
command="git $cmd_args"
844865
test_submodule_recursing_with_args_common "$command"
845866

846867
RESULTDS=success
@@ -957,7 +978,7 @@ test_submodule_switch_recursing_with_args () {
957978
# away local changes in the superproject is allowed.
958979
test_submodule_forced_switch_recursing_with_args () {
959980
cmd_args="$1"
960-
command="git $cmd_args --recurse-submodules"
981+
command="git $cmd_args"
961982
test_submodule_recursing_with_args_common "$command"
962983

963984
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ git_rebase () {
1717
git status -su >actual &&
1818
ls -1pR * >>actual &&
1919
test_cmp expect actual &&
20-
git rebase "$1"
20+
$OVERWRITING_FAIL git rebase "$1"
2121
}
2222

23-
test_submodule_switch "git_rebase"
23+
test_submodule_switch_func "git_rebase"
2424

2525
git_rebase_interactive () {
2626
git status -su >expect &&
@@ -35,10 +35,10 @@ git_rebase_interactive () {
3535
test_cmp expect actual &&
3636
set_fake_editor &&
3737
echo "fake-editor.sh" >.git/info/exclude &&
38-
git rebase -i "$1"
38+
$OVERWRITING_FAIL git rebase -i "$1"
3939
}
4040

41-
test_submodule_switch "git_rebase_interactive"
41+
test_submodule_switch_func "git_rebase_interactive"
4242

4343
test_expect_success 'rebase interactive ignores modified submodules' '
4444
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ git_revert () {
1515
git status -su >expect &&
1616
ls -1pR * >>expect &&
1717
tar cf "$TRASH_DIRECTORY/tmp.tar" * &&
18+
$OVERWRITING_FAIL git checkout "$1" &&
19+
if test -n "$OVERWRITING_FAIL"
20+
then
21+
return
22+
fi &&
1823
git checkout "$1" &&
1924
git revert HEAD &&
2025
rm -rf * &&
@@ -26,6 +31,6 @@ git_revert () {
2631
}
2732

2833
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
29-
test_submodule_switch "git_revert"
34+
test_submodule_switch_func "git_revert"
3035

3136
test_done

t/t3906-stash-submodule.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ test_description='stash can handle submodules'
88
git_stash () {
99
git status -su >expect &&
1010
ls -1pR * >>expect &&
11-
git read-tree -u -m "$1" &&
11+
$OVERWRITING_FAIL git read-tree -u -m "$1" &&
12+
if test -n "$OVERWRITING_FAIL"
13+
then
14+
return
15+
fi &&
1216
git stash &&
1317
git status -su >actual &&
1418
ls -1pR * >>actual &&
@@ -19,7 +23,7 @@ git_stash () {
1923
KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
2024
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
2125
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
22-
test_submodule_switch "git_stash"
26+
test_submodule_switch_func "git_stash"
2327

2428
setup_basic () {
2529
test_when_finished "rm -rf main sub" &&

t/t4137-apply-submodule.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ test_description='git apply handling submodules'
66
. "$TEST_DIRECTORY"/lib-submodule-update.sh
77

88
apply_index () {
9-
git diff --ignore-submodules=dirty "..$1" | git apply --index -
9+
git diff --ignore-submodules=dirty "..$1" >diff &&
10+
$OVERWRITING_FAIL git apply --index - <diff
1011
}
1112

12-
test_submodule_switch "apply_index"
13+
test_submodule_switch_func "apply_index"
1314

1415
apply_3way () {
15-
git diff --ignore-submodules=dirty "..$1" | git apply --3way -
16+
git diff --ignore-submodules=dirty "..$1" >diff &&
17+
$OVERWRITING_FAIL git apply --3way - <diff
1618
}
1719

18-
test_submodule_switch "apply_3way"
20+
test_submodule_switch_func "apply_3way"
1921

2022
test_done

t/t4255-am-submodule.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ test_description='git am handling submodules'
66
. "$TEST_DIRECTORY"/lib-submodule-update.sh
77

88
am () {
9-
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am -
9+
git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
10+
$OVERWRITING_FAIL git am - <patch
1011
}
1112

12-
test_submodule_switch "am"
13+
test_submodule_switch_func "am"
1314

1415
am_3way () {
15-
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way -
16+
git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
17+
$OVERWRITING_FAIL git am --3way - <patch
1618
}
1719

1820
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
19-
test_submodule_switch "am_3way"
21+
test_submodule_switch_func "am_3way"
2022

2123
test_expect_success 'setup diff.submodule' '
2224
test_commit one &&

t/t5572-pull-submodule.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ reset_branch_to_HEAD () {
1313

1414
git_pull () {
1515
reset_branch_to_HEAD "$1" &&
16-
git pull
16+
$OVERWRITING_FAIL git pull
1717
}
1818

1919
# pulls without conflicts
20-
test_submodule_switch "git_pull"
20+
test_submodule_switch_func "git_pull"
2121

2222
git_pull_ff () {
2323
reset_branch_to_HEAD "$1" &&
24-
git pull --ff
24+
$OVERWRITING_FAIL git pull --ff
2525
}
2626

27-
test_submodule_switch "git_pull_ff"
27+
test_submodule_switch_func "git_pull_ff"
2828

2929
git_pull_ff_only () {
3030
reset_branch_to_HEAD "$1" &&
31-
git pull --ff-only
31+
$OVERWRITING_FAIL git pull --ff-only
3232
}
3333

34-
test_submodule_switch "git_pull_ff_only"
34+
test_submodule_switch_func "git_pull_ff_only"
3535

3636
git_pull_noff () {
3737
reset_branch_to_HEAD "$1" &&
38-
git pull --no-ff
38+
$OVERWRITING_FAIL git pull --no-ff
3939
}
4040

4141
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
4242
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
43-
test_submodule_switch "git_pull_noff"
43+
test_submodule_switch_func "git_pull_noff"
4444

4545
test_expect_success 'pull --recurse-submodule setup' '
4646
test_create_repo child &&

t/t6041-bisect-submodule.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ git_bisect () {
1010
ls -1pR * >>expect &&
1111
tar cf "$TRASH_DIRECTORY/tmp.tar" * &&
1212
GOOD=$(git rev-parse --verify HEAD) &&
13-
git checkout "$1" &&
13+
$OVERWRITING_FAIL git checkout "$1" &&
14+
if test -n "$OVERWRITING_FAIL"
15+
then
16+
return
17+
fi &&
1418
echo "foo" >bar &&
1519
git add bar &&
1620
git commit -m "bisect bad" &&
@@ -27,6 +31,6 @@ git_bisect () {
2731
git bisect bad $BAD
2832
}
2933

30-
test_submodule_switch "git_bisect"
34+
test_submodule_switch_func "git_bisect"
3135

3236
test_done

t/t7112-reset-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ test_submodule_switch_recursing_with_args "reset --keep"
1212

1313
test_submodule_forced_switch_recursing_with_args "reset --hard"
1414

15-
test_submodule_switch "git reset --keep"
15+
test_submodule_switch "reset --keep"
1616

17-
test_submodule_switch "git reset --merge"
17+
test_submodule_switch "reset --merge"
1818

19-
test_submodule_forced_switch "git reset --hard"
19+
test_submodule_forced_switch "reset --hard"
2020

2121
test_done

t/t7613-merge-submodule.sh

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

88
# merges without conflicts
9-
test_submodule_switch "git merge"
9+
test_submodule_switch "merge"
1010

11-
test_submodule_switch "git merge --ff"
11+
test_submodule_switch "merge --ff"
1212

13-
test_submodule_switch "git merge --ff-only"
13+
test_submodule_switch "merge --ff-only"
1414

1515
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
1616
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
17-
test_submodule_switch "git merge --no-ff"
17+
test_submodule_switch "merge --no-ff"
1818

1919
test_done

0 commit comments

Comments
 (0)