Skip to content

Commit

Permalink
submodule deinit: unset core.worktree
Browse files Browse the repository at this point in the history
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 984cd77 (submodule deinit: unset core.worktree,
2018-06-18), which was reverted as part of f178c13 (Revert "Merge
branch 'sb/submodule-core-worktree'", 2018-09-07)

The whole series was reverted as the offending commit e983175
(submodule: ensure core.worktree is set after update, 2018-06-18)
was relied on by other commits such as 984cd77.

Keep the offending commit reverted, but its functionality came back via
4d6d6ef (Merge branch 'sb/submodule-update-in-c', 2018-09-17), such
that we can reintroduce 984cd77 now.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
stefanbeller authored and gitster committed Dec 26, 2018
1 parent 820a647 commit 8eda5ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions builtin/submodule--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ static void deinit_submodule(const char *path, const char *prefix,
if (!(flags & OPT_QUIET))
printf(format, displaypath);

submodule_unset_core_worktree(sub);

strbuf_release(&sb_rm);
}

Expand Down
2 changes: 1 addition & 1 deletion t/lib-submodule-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ reset_work_tree_to_interested () {
then
mkdir -p submodule_update/.git/modules/sub1/modules &&
cp -r submodule_update_repo/.git/modules/sub1/modules/sub2 submodule_update/.git/modules/sub1/modules/sub2
GIT_WORK_TREE=. git -C submodule_update/.git/modules/sub1/modules/sub2 config --unset core.worktree
# core.worktree is unset for sub2 as it is not checked out
fi &&
# indicate we are interested in the submodule:
git -C submodule_update config submodule.sub1.url "bogus" &&
Expand Down
5 changes: 5 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,11 @@ test_expect_success 'submodule deinit should remove the whole submodule section
rmdir init
'

test_expect_success 'submodule deinit should unset core.worktree' '
test_path_is_file .git/modules/example/config &&
test_must_fail git config -f .git/modules/example/config core.worktree
'

test_expect_success 'submodule deinit from subdirectory' '
git submodule update --init &&
git config submodule.example.foo bar &&
Expand Down

0 comments on commit 8eda5ef

Please sign in to comment.