Skip to content

Commit 670703e

Browse files
committed
Merge branch 'mp/absorb-submodule-git-dir-upon-deinit'
"git submodule deinit" for a submodule whose .git metadata directory is embedded in its working tree refused to work, until the submodule gets converted to use the "absorbed" form where the metadata directory is stored in superproject, and a gitfile at the top-level of the working tree of the submodule points at it. The command is taught to convert such submodules to the absorbed form as needed. * mp/absorb-submodule-git-dir-upon-deinit: submodule: absorb git dir instead of dying on deinit
2 parents d67fc4b + 0adc8ba commit 670703e

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)