Skip to content

Commit a65a53b

Browse files
committed
Merge branch 'jl/submodule-mv-checkout-caveat'
With a submodule that was initialized in an old fashioned way without gitlinks, switching branches in the superproject between the one with and without the submodule may leave the submodule working tree with its embedded repository behind, as there may be unexpendable state there. Document and warn users about this. * jl/submodule-mv-checkout-caveat: rm: better document side effects when removing a submodule mv: better document side effects when moving a submodule
2 parents 5e72e71 + bbad9f9 commit a65a53b

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

Documentation/git-mv.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ core.worktree setting to make the submodule work in the new location.
5252
It also will attempt to update the submodule.<name>.path setting in
5353
the linkgit:gitmodules[5] file and stage that file (unless -n is used).
5454

55+
BUGS
56+
----
57+
Each time a superproject update moves a populated submodule (e.g. when
58+
switching between commits before and after the move) a stale submodule
59+
checkout will remain in the old location and an empty directory will
60+
appear in the new location. To populate the submodule again in the new
61+
location the user will have to run "git submodule update"
62+
afterwards. Removing the old directory is only safe when it uses a
63+
gitfile, as otherwise the history of the submodule will be deleted
64+
too. Both steps will be obsolete when recursive submodule update has
65+
been implemented.
66+
5567
GIT
5668
---
5769
Part of the linkgit:git[1] suite

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 &&

t/t7001-mv.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,25 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
442442
git diff-files --quiet -- sub .gitmodules
443443
'
444444

445+
test_expect_success 'checking out a commit before submodule moved needs manual updates' '
446+
git mv sub sub2 &&
447+
git commit -m "moved sub to sub2" &&
448+
git checkout -q HEAD^ 2>actual &&
449+
echo "warning: unable to rmdir sub2: Directory not empty" >expected &&
450+
test_i18ncmp expected actual &&
451+
git status -s sub2 >actual &&
452+
echo "?? sub2/" >expected &&
453+
test_cmp expected actual &&
454+
! test -f sub/.git &&
455+
test -f sub2/.git &&
456+
git submodule update &&
457+
test -f sub/.git &&
458+
rm -rf sub2 &&
459+
git diff-index --exit-code HEAD &&
460+
git update-index --refresh &&
461+
git diff-files --quiet -- sub .gitmodules &&
462+
git status -s sub2 >actual &&
463+
! test -s actual
464+
'
465+
445466
test_done

0 commit comments

Comments
 (0)