Skip to content

Commit 9f08090

Browse files
committed
Merge branch 'pb/recurse-submodules-fix' into jch
* pb/recurse-submodules-fix: t/lib-submodule-update: add test removing nested submodules unpack-trees: check for missing submodule directory in merged_entry unpack-trees: remove outdated description for verify_clean_submodule t/lib-submodule-update: move a test to the right section t/lib-submodule-update: remove outdated test description t7112: remove mention of KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED
2 parents 99247a4 + 846f34d commit 9f08090

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

t/lib-submodule-update.sh

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ test_submodule_content () {
297297
# - Directory containing tracked files replaced by submodule
298298
# - Submodule replaced by tracked files in directory
299299
# - Submodule replaced by tracked file with the same name
300-
# - tracked file replaced by submodule
300+
# - Tracked file replaced by submodule
301301
#
302302
# The default is that submodule contents aren't changed until "git submodule
303303
# update" is run. And even then that command doesn't delete the work tree of
@@ -621,11 +621,13 @@ test_submodule_forced_switch () {
621621
# - Directory containing tracked files replaced by submodule
622622
# - Submodule replaced by tracked files in directory
623623
# - Submodule replaced by tracked file with the same name
624-
# - tracked file replaced by submodule
624+
# - Tracked file replaced by submodule
625625
#
626626
# New test cases
627627
# - Removing a submodule with a git directory absorbs the submodules
628628
# git directory first into the superproject.
629+
# - Switching from no submodule to nested submodules
630+
# - Switching from nested submodules to no submodule
629631

630632
# Internal function; use test_submodule_switch_recursing_with_args() or
631633
# test_submodule_forced_switch_recursing_with_args() instead.
@@ -658,22 +660,6 @@ test_submodule_recursing_with_args_common() {
658660
test_submodule_content sub1 origin/add_sub1
659661
)
660662
'
661-
test_expect_success "$command: submodule branch is not changed, detach HEAD instead" '
662-
prolog &&
663-
reset_work_tree_to_interested add_sub1 &&
664-
(
665-
cd submodule_update &&
666-
git -C sub1 checkout -b keep_branch &&
667-
git -C sub1 rev-parse HEAD >expect &&
668-
git branch -t modify_sub1 origin/modify_sub1 &&
669-
$command modify_sub1 &&
670-
test_superproject_content origin/modify_sub1 &&
671-
test_submodule_content sub1 origin/modify_sub1 &&
672-
git -C sub1 rev-parse keep_branch >actual &&
673-
test_cmp expect actual &&
674-
test_must_fail git -C sub1 symbolic-ref HEAD
675-
)
676-
'
677663

678664
# Replacing a tracked file with a submodule produces a checked out submodule
679665
test_expect_success "$command: replace tracked file with submodule checks out submodule" '
@@ -699,6 +685,19 @@ test_submodule_recursing_with_args_common() {
699685
test_submodule_content sub1 origin/replace_directory_with_sub1
700686
)
701687
'
688+
# Switching to a commit with nested submodules recursively checks them out
689+
test_expect_success "$command: nested submodules are checked out" '
690+
prolog &&
691+
reset_work_tree_to_interested no_submodule &&
692+
(
693+
cd submodule_update &&
694+
git branch -t modify_sub1_recursively origin/modify_sub1_recursively &&
695+
$command modify_sub1_recursively &&
696+
test_superproject_content origin/modify_sub1_recursively &&
697+
test_submodule_content sub1 origin/modify_sub1_recursively &&
698+
test_submodule_content -C sub1 sub2 origin/modify_sub1_recursively
699+
)
700+
'
702701

703702
######################## Disappearing submodule #######################
704703
# Removing a submodule removes its work tree ...
@@ -762,6 +761,21 @@ test_submodule_recursing_with_args_common() {
762761
)
763762
'
764763

764+
# Switching to a commit without nested submodules removes their worktrees
765+
test_expect_success "$command: worktrees of nested submodules are removed" '
766+
prolog &&
767+
reset_work_tree_to_interested add_nested_sub &&
768+
(
769+
cd submodule_update &&
770+
git branch -t no_submodule origin/no_submodule &&
771+
$command no_submodule &&
772+
test_superproject_content origin/no_submodule &&
773+
! test_path_is_dir sub1 &&
774+
test_must_fail git config -f .git/modules/sub1/config core.worktree &&
775+
test_must_fail git config -f .git/modules/sub1/modules/sub2/config core.worktree
776+
)
777+
'
778+
765779
########################## Modified submodule #########################
766780
# Updating a submodule sha1 updates the submodule's work tree
767781
test_expect_success "$command: modified submodule updates submodule work tree" '
@@ -789,6 +803,23 @@ test_submodule_recursing_with_args_common() {
789803
test_submodule_content sub1 origin/add_sub1
790804
)
791805
'
806+
# Updating a submodule does not touch the currently checked out branch in the submodule
807+
test_expect_success "$command: submodule branch is not changed, detach HEAD instead" '
808+
prolog &&
809+
reset_work_tree_to_interested add_sub1 &&
810+
(
811+
cd submodule_update &&
812+
git -C sub1 checkout -b keep_branch &&
813+
git -C sub1 rev-parse HEAD >expect &&
814+
git branch -t modify_sub1 origin/modify_sub1 &&
815+
$command modify_sub1 &&
816+
test_superproject_content origin/modify_sub1 &&
817+
test_submodule_content sub1 origin/modify_sub1 &&
818+
git -C sub1 rev-parse keep_branch >actual &&
819+
test_cmp expect actual &&
820+
test_must_fail git -C sub1 symbolic-ref HEAD
821+
)
822+
'
792823
}
793824

794825
# Declares and invokes several tests that, in various situations, checks that
@@ -908,7 +939,6 @@ test_submodule_switch_recursing_with_args () {
908939
)
909940
'
910941

911-
# recursing deeper than one level doesn't work yet.
912942
test_expect_success "$command: modified submodule updates submodule recursively" '
913943
prolog &&
914944
reset_work_tree_to_interested add_nested_sub &&

t/t7112-reset-submodule.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ test_description='reset can handle submodules'
55
. ./test-lib.sh
66
. "$TEST_DIRECTORY"/lib-submodule-update.sh
77

8-
KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1
98
KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1
109
KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1
1110

unpack-trees.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,9 +1815,6 @@ static void invalidate_ce_path(const struct cache_entry *ce,
18151815
/*
18161816
* Check that checking out ce->sha1 in subdir ce->name is not
18171817
* going to overwrite any working files.
1818-
*
1819-
* Currently, git does not checkout subprojects during a superproject
1820-
* checkout, so it is not going to overwrite anything.
18211818
*/
18221819
static int verify_clean_submodule(const char *old_sha1,
18231820
const struct cache_entry *ce,
@@ -2067,7 +2064,7 @@ static int merged_entry(const struct cache_entry *ce,
20672064
}
20682065
invalidate_ce_path(merge, o);
20692066

2070-
if (submodule_from_ce(ce)) {
2067+
if (submodule_from_ce(ce) && file_exists(ce->name)) {
20712068
int ret = check_submodule_move_head(ce, NULL,
20722069
oid_to_hex(&ce->oid),
20732070
o);
@@ -2096,7 +2093,7 @@ static int merged_entry(const struct cache_entry *ce,
20962093
invalidate_ce_path(old, o);
20972094
}
20982095

2099-
if (submodule_from_ce(ce)) {
2096+
if (submodule_from_ce(ce) && file_exists(ce->name)) {
21002097
int ret = check_submodule_move_head(ce, oid_to_hex(&old->oid),
21012098
oid_to_hex(&ce->oid),
21022099
o);

0 commit comments

Comments
 (0)