Skip to content

Commit 1cbd183

Browse files
jlehmanngitster
authored andcommitted
mv: better document side effects when moving a submodule
The "Submodules" section of the "git mv" documentation mentions what will happen when a submodule with a gitfile gets moved with newer git. But it doesn't talk about what happens when the user changes between commits before and after the move, which does not update the work tree like using the mv 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. Reported-by: George Papanikolaou <[email protected]> Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 932f7e4 commit 1cbd183

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-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

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)