Skip to content

Commit 920f2ea

Browse files
committed
Merge branch 'sb/mv-submodule-fix' into HEAD
"git mv old new" did not adjust the path for a submodule that lives as a subdirectory inside old/ directory correctly. * sb/mv-submodule-fix: mv: allow moving nested submodules
2 parents e9ef83a + a127331 commit 920f2ea

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

builtin/mv.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,18 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
252252
int pos;
253253
if (show_only || verbose)
254254
printf(_("Renaming %s to %s\n"), src, dst);
255-
if (!show_only && mode != INDEX) {
256-
if (rename(src, dst) < 0 && !ignore_errors)
257-
die_errno(_("renaming '%s' failed"), src);
258-
if (submodule_gitfile[i]) {
259-
if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
260-
connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
261-
if (!update_path_in_gitmodules(src, dst))
262-
gitmodules_modified = 1;
263-
}
255+
if (show_only)
256+
continue;
257+
if (mode != INDEX && rename(src, dst) < 0) {
258+
if (ignore_errors)
259+
continue;
260+
die_errno(_("renaming '%s' failed"), src);
261+
}
262+
if (submodule_gitfile[i]) {
263+
if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
264+
connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
265+
if (!update_path_in_gitmodules(src, dst))
266+
gitmodules_modified = 1;
264267
}
265268

266269
if (mode == WORKING_DIRECTORY)

t/t7001-mv.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '
292292
echo content >file &&
293293
git add file &&
294294
git commit -m "added sub and file" &&
295+
mkdir -p deep/directory/hierachy &&
296+
git submodule add ./. deep/directory/hierachy/sub &&
297+
git commit -m "added another submodule" &&
295298
git branch submodule
296299
'
297300

@@ -475,4 +478,17 @@ test_expect_success 'mv -k does not accidentally destroy submodules' '
475478
git checkout .
476479
'
477480

481+
test_expect_success 'moving a submodule in nested directories' '
482+
(
483+
cd deep &&
484+
git mv directory ../ &&
485+
# git status would fail if the update of linking git dir to
486+
# work dir of the submodule failed.
487+
git status &&
488+
git config -f ../.gitmodules submodule.deep/directory/hierachy/sub.path >../actual &&
489+
echo "directory/hierachy/sub" >../expect
490+
) &&
491+
test_cmp actual expect
492+
'
493+
478494
test_done

0 commit comments

Comments
 (0)