Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submodule: absorb git dir instead of dying on deinit #1078

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions builtin/submodule--helper.c
Expand Up @@ -1539,16 +1539,17 @@ static void deinit_submodule(const char *path, const char *prefix,
struct strbuf sb_rm = STRBUF_INIT;
const char *format;

/*
* protect submodules containing a .git directory
* NEEDSWORK: instead of dying, automatically call
* absorbgitdirs and (possibly) warn.
*/
if (is_directory(sub_git_dir))
die(_("Submodule work tree '%s' contains a .git "
"directory (use 'rm -rf' if you really want "
"to remove it including all of its history)"),
displaypath);
if (is_directory(sub_git_dir)) {
if (!(flags & OPT_QUIET))
warning(_("Submodule work tree '%s' contains a .git "
"directory. This will be replaced with a "
".git file by using absorbgitdirs."),
displaypath);

absorb_git_dir_into_superproject(path,
ABSORB_GITDIR_RECURSE_SUBMODULES);

}

if (!(flags & OPT_FORCE)) {
struct child_process cp_rm = CHILD_PROCESS_INIT;
Expand Down
11 changes: 5 additions & 6 deletions t/t7400-submodule-basic.sh
Expand Up @@ -1182,18 +1182,17 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
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 &&
(
cd init &&
rm .git &&
cp -R ../.git/modules/example .git &&
mv ../.git/modules/example .git &&
GIT_WORK_TREE=. git config --unset core.worktree
) &&
test_must_fail git submodule deinit init &&
test_must_fail git submodule deinit -f init &&
test -d init/.git &&
test -n "$(git config --get-regexp "submodule\.example\.")"
git submodule deinit init &&
test_path_is_missing init/.git &&
test -z "$(git config --get-regexp "submodule\.example\.")"
'

test_expect_success 'submodule with UTF-8 name' '
Expand Down