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
This commit is contained in:
Junio C Hamano 2021-12-10 14:35:15 -08:00
commit 670703e9d6
2 changed files with 16 additions and 16 deletions

View file

@ -1503,16 +1503,17 @@ static void deinit_submodule(const char *path, const char *prefix,
struct strbuf sb_rm = STRBUF_INIT; struct strbuf sb_rm = STRBUF_INIT;
const char *format; const char *format;
/* if (is_directory(sub_git_dir)) {
* protect submodules containing a .git directory if (!(flags & OPT_QUIET))
* NEEDSWORK: instead of dying, automatically call warning(_("Submodule work tree '%s' contains a .git "
* absorbgitdirs and (possibly) warn. "directory. This will be replaced with a "
*/ ".git file by using absorbgitdirs."),
if (is_directory(sub_git_dir)) displaypath);
die(_("Submodule work tree '%s' contains a .git "
"directory (use 'rm -rf' if you really want " absorb_git_dir_into_superproject(path,
"to remove it including all of its history)"), ABSORB_GITDIR_RECURSE_SUBMODULES);
displaypath);
}
if (!(flags & OPT_FORCE)) { if (!(flags & OPT_FORCE)) {
struct child_process cp_rm = CHILD_PROCESS_INIT; struct child_process cp_rm = CHILD_PROCESS_INIT;

View file

@ -1182,18 +1182,17 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
rmdir init example2 rmdir init example2
' '
test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' '
git submodule update --init && git submodule update --init &&
( (
cd init && cd init &&
rm .git && rm .git &&
cp -R ../.git/modules/example .git && mv ../.git/modules/example .git &&
GIT_WORK_TREE=. git config --unset core.worktree GIT_WORK_TREE=. git config --unset core.worktree
) && ) &&
test_must_fail git submodule deinit init && git submodule deinit init &&
test_must_fail git submodule deinit -f init && test_path_is_missing init/.git &&
test -d init/.git && test -z "$(git config --get-regexp "submodule\.example\.")"
test -n "$(git config --get-regexp "submodule\.example\.")"
' '
test_expect_success 'submodule with UTF-8 name' ' test_expect_success 'submodule with UTF-8 name' '