Skip to content

Commit bbad9f9

Browse files
jlehmanngitster
authored andcommitted
rm: better document side effects when removing a submodule
The "Submodules" section of the "git rm" documentation mentions what will happen when a submodule with a gitfile gets removed with newer git. But it doesn't talk about what happens when the user changes between commits before and after the removal, which does not remove the submodule from the work tree like using the rm command did the first time. Explain what happens and what the user has to do manually to fix that in the new BUGS section. Also document this behavior in a new test. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1cbd183 commit bbad9f9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Documentation/git-rm.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ of files and subdirectories under the `Documentation/` directory.
170170
(i.e. you are listing the files explicitly), it
171171
does not remove `subdir/git-foo.sh`.
172172

173+
BUGS
174+
----
175+
Each time a superproject update removes a populated submodule
176+
(e.g. when switching between commits before and after the removal) a
177+
stale submodule checkout will remain in the old location. Removing the
178+
old directory is only safe when it uses a gitfile, as otherwise the
179+
history of the submodule will be deleted too. This step will be
180+
obsolete when recursive submodule update has been implemented.
181+
173182
SEE ALSO
174183
--------
175184
linkgit:git-add[1]

t/t3600-rm.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,22 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc
705705
rm -rf submod
706706
'
707707

708+
test_expect_success 'checking out a commit after submodule removal needs manual updates' '
709+
git commit -m "submodule removal" submod &&
710+
git checkout HEAD^ &&
711+
git submodule update &&
712+
git checkout -q HEAD^ 2>actual &&
713+
git checkout -q master 2>actual &&
714+
echo "warning: unable to rmdir submod: Directory not empty" >expected &&
715+
test_i18ncmp expected actual &&
716+
git status -s submod >actual &&
717+
echo "?? submod/" >expected &&
718+
test_cmp expected actual &&
719+
rm -rf submod &&
720+
git status -s -uno --ignore-submodules=none > actual &&
721+
! test -s actual
722+
'
723+
708724
test_expect_success 'rm of d/f when d has become a non-directory' '
709725
rm -rf d &&
710726
mkdir d &&

0 commit comments

Comments
 (0)