submodule deinit: unset core.worktree

When a submodule is deinit'd, the working tree is gone, so the setting of core.worktree is bogus. Unset it. As we covered the only other case in which a submodule loses its working tree in the earlier step (i.e. switching branches of top-level project to move to a commit that did not have the submodule), this makes the code always maintain core.worktree correctly unset when there is no working tree for a submodule. This re-introduces 984cd77ddb (submodule deinit: unset core.worktree, 2018-06-18), which was reverted as part of f178c13fda (Revert "Merge branch 'sb/submodule-core-worktree'", 2018-09-07) The whole series was reverted as the offending commit e98317508c (submodule: ensure core.worktree is set after update, 2018-06-18) was relied on by other commits such as 984cd77ddb. Keep the offending commit reverted, but its functionality came back via 4d6d6ef1fc (Merge branch 'sb/submodule-update-in-c', 2018-09-17), such that we can reintroduce 984cd77ddb now. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Dec 14, 2018 at 15:59 UTC 8eda5efa1269a6117b86a97a309eb3a195b5f087
3 files changed +8 -1
builtin/submodule--helper.c
+2
@@ -1131,6 +1131,8 @@ static void deinit_submodule(const char *path, const char *prefix,
1131 if (!(flags & OPT_QUIET))
1132 printf(format, displaypath);
1133
1134 + submodule_unset_core_worktree(sub);
1135 +
1136 strbuf_release(&sb_rm);
1137 }
1138
t/lib-submodule-update.sh
+1 -1
@@ -235,7 +235,7 @@ reset_work_tree_to_interested () {
235 then
236 mkdir -p submodule_update/.git/modules/sub1/modules &&
237 cp -r submodule_update_repo/.git/modules/sub1/modules/sub2 submodule_update/.git/modules/sub1/modules/sub2
238 - GIT_WORK_TREE=. git -C submodule_update/.git/modules/sub1/modules/sub2 config --unset core.worktree
238 + # core.worktree is unset for sub2 as it is not checked out
239 fi &&
240 # indicate we are interested in the submodule:
241 git -C submodule_update config submodule.sub1.url "bogus" &&
t/t7400-submodule-basic.sh
+5
@@ -984,6 +984,11 @@ test_expect_success 'submodule deinit should remove the whole submodule section
984 rmdir init
985 '
986
987 +test_expect_success 'submodule deinit should unset core.worktree' '
988 + test_path_is_file .git/modules/example/config &&
989 + test_must_fail git config -f .git/modules/example/config core.worktree
990 +'
991 +
992 test_expect_success 'submodule deinit from subdirectory' '
993 git submodule update --init &&
994 git config submodule.example.foo bar &&