From 55856a35b20dae2499d4e0b23551c7ba9a33baf2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 27 Dec 2016 11:03:14 -0800 Subject: rm: absorb a submodules git dir before deletion When deleting a submodule, we need to keep the actual git directory around, such that we do not lose local changes in there and at a later checkout of the submodule we don't need to clone it again. Now that the functionality is available to absorb the git directory of a submodule, rewrite the checking in git-rm to not complain, but rather relocate the git directories inside the superproject. An alternative solution was discussed to have a function `depopulate_submodule`. That would couple the check for its git directory and possible relocation before the the removal, such that it is less likely to miss the check in the future. But the indirection with such a function added seemed also complex. The reason for that was that this possible move of the git directory was also implemented in `ok_to_remove_submodule`, such that this function could truthfully answer whether it is ok to remove the submodule. The solution proposed here defers all these checks to the caller. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- t/t3600-rm.sh | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 't') diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 14f0edca2b..030d6c32ae 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -585,26 +585,22 @@ test_expect_success 'rm of a conflicted unpopulated submodule succeeds' ' test_cmp expect actual ' -test_expect_success 'rm of a populated submodule with a .git directory fails even when forced' ' +test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' ' git checkout -f master && git reset --hard && git submodule update && (cd submod && rm .git && cp -R ../.git/modules/sub .git && - GIT_WORK_TREE=. git config --unset core.worktree + GIT_WORK_TREE=. git config --unset core.worktree && + rm -r ../.git/modules/sub ) && - test_must_fail git rm submod && - test -d submod && - test -d submod/.git && - git status -s -uno --ignore-submodules=none > actual && - ! test -s actual && - test_must_fail git rm -f submod && - test -d submod && - test -d submod/.git && - git status -s -uno --ignore-submodules=none > actual && - ! test -s actual && - rm -rf submod + git rm submod 2>output.err && + ! test -d submod && + ! test -d submod/.git && + git status -s -uno --ignore-submodules=none >actual && + test -s actual && + test_i18ngrep Migrating output.err ' cat >expect.deepmodified < actual && - ! test -s actual && - test_must_fail git rm -f submod && - test -d submod && - test -d submod/subsubmod/.git && - git status -s -uno --ignore-submodules=none > actual && - ! test -s actual && - rm -rf submod + git rm submod 2>output.err && + ! test -d submod && + ! test -d submod/subsubmod/.git && + git status -s -uno --ignore-submodules=none >actual && + test -s actual && + test_i18ngrep Migrating output.err ' test_expect_success 'checking out a commit after submodule removal needs manual updates' ' - git commit -m "submodule removal" submod && + git commit -m "submodule removal" submod .gitmodules && git checkout HEAD^ && git submodule update && git checkout -q HEAD^ 2>actual && -- cgit v1.2.3