Skip to content

Commit 0adc8ba

Browse files
mugdhapattnaikgitster
authored andcommitted
submodule: absorb git dir instead of dying on deinit
Currently, running 'git submodule deinit' on repos where the submodule's '.git' is a directory, aborts with a message that is not exactly user friendly. Let's change this to instead warn the user that the .git/ directory has been absorbed into the superproject. The rest of the deinit function can operate as it already does with new-style submodules. In one test, we used to require "git submodule deinit" to fail even with the "--force" option when the submodule's .git/ directory is not absorbed. Adjust it to expect the operation to pass. Suggested-by: Atharva Raykar <[email protected]> Signed-off-by: Mugdha Pattnaik <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 106298f commit 0adc8ba

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

builtin/submodule--helper.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,16 +1503,17 @@ static void deinit_submodule(const char *path, const char *prefix,
15031503
struct strbuf sb_rm = STRBUF_INIT;
15041504
const char *format;
15051505

1506-
/*
1507-
* protect submodules containing a .git directory
1508-
* NEEDSWORK: instead of dying, automatically call
1509-
* absorbgitdirs and (possibly) warn.
1510-
*/
1511-
if (is_directory(sub_git_dir))
1512-
die(_("Submodule work tree '%s' contains a .git "
1513-
"directory (use 'rm -rf' if you really want "
1514-
"to remove it including all of its history)"),
1515-
displaypath);
1506+
if (is_directory(sub_git_dir)) {
1507+
if (!(flags & OPT_QUIET))
1508+
warning(_("Submodule work tree '%s' contains a .git "
1509+
"directory. This will be replaced with a "
1510+
".git file by using absorbgitdirs."),
1511+
displaypath);
1512+
1513+
absorb_git_dir_into_superproject(path,
1514+
ABSORB_GITDIR_RECURSE_SUBMODULES);
1515+
1516+
}
15161517

15171518
if (!(flags & OPT_FORCE)) {
15181519
struct child_process cp_rm = CHILD_PROCESS_INIT;

t/t7400-submodule-basic.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,18 +1182,17 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
11821182
rmdir init example2
11831183
'
11841184

1185-
test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1185+
test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' '
11861186
git submodule update --init &&
11871187
(
11881188
cd init &&
11891189
rm .git &&
1190-
cp -R ../.git/modules/example .git &&
1190+
mv ../.git/modules/example .git &&
11911191
GIT_WORK_TREE=. git config --unset core.worktree
11921192
) &&
1193-
test_must_fail git submodule deinit init &&
1194-
test_must_fail git submodule deinit -f init &&
1195-
test -d init/.git &&
1196-
test -n "$(git config --get-regexp "submodule\.example\.")"
1193+
git submodule deinit init &&
1194+
test_path_is_missing init/.git &&
1195+
test -z "$(git config --get-regexp "submodule\.example\.")"
11971196
'
11981197

11991198
test_expect_success 'submodule with UTF-8 name' '

0 commit comments

Comments
 (0)