{"thread":{"id":"42075","subject":"[PATCH] mv: allow moving nested submodules","startedAt":"2016-04-19T18:32:04Z","lastAt":"2016-04-19T18:32:04Z","messageCount":1,"participants":["Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"283822","messageId":"1461090724-16325-1-git-send-email-sbeller@google.com","threadId":"42075","inReplyTo":null,"subject":"[PATCH] mv: allow moving nested submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-19T18:32:04Z","receivedAt":"2016-04-19T18:32:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When directories are moved using `git mv` all files in the directory\nhave been just moved, but no further action was taken on them. This\nwas done by assigning the mode = WORKING_DIRECTORY to the files\ninside a moved directory.\n\nsubmodules however need to update their link to the git directory as\nwell as updates to the .gitmodules file. By removing the condition of\n`mode != INDEX` (the remaining modes are BOTH and WORKING_DIRECTORY) for\nthe required submodule actions, we perform these for submodules in a\nmoved directory.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n\n> Can you do only the 2/2 on top of maint (or maint-2.6) for now then?\n\nThis is developed on maint-2.6.\n\n builtin/mv.c  | 22 +++++++++++++---------\n t/t7001-mv.sh | 16 ++++++++++++++++\n 2 files changed, 29 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex d1d4316..77f3ec5 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -251,15 +251,19 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tint pos;\n \t\tif (show_only || verbose)\n \t\t\tprintf(_(\"Renaming %s to %s\\n\"), src, dst);\n-\t\tif (!show_only && mode != INDEX) {\n-\t\t\tif (rename(src, dst) < 0 && !ignore_errors)\n-\t\t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n-\t\t\tif (submodule_gitfile[i]) {\n-\t\t\t\tif (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)\n-\t\t\t\t\tconnect_work_tree_and_git_dir(dst, submodule_gitfile[i]);\n-\t\t\t\tif (!update_path_in_gitmodules(src, dst))\n-\t\t\t\t\tgitmodules_modified = 1;\n-\t\t\t}\n+\t\tif (show_only)\n+\t\t\tcontinue;\n+\t\tif (mode != INDEX &&\n+\t\t    rename(src, dst) < 0) {\n+\t\t\tif (ignore_errors)\n+\t\t\t\tcontinue;\n+\t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n+\t\t}\n+\t\tif (submodule_gitfile[i]) {\n+\t\t\tif (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)\n+\t\t\t\tconnect_work_tree_and_git_dir(dst, submodule_gitfile[i]);\n+\t\t\tif (!update_path_in_gitmodules(src, dst))\n+\t\t\t\tgitmodules_modified = 1;\n \t\t}\n \n \t\tif (mode == WORKING_DIRECTORY)\ndiff --git a/t/t7001-mv.sh b/t/t7001-mv.sh\nindex 7b56081..fcfc953 100755\n--- a/t/t7001-mv.sh\n+++ b/t/t7001-mv.sh\n@@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '\n \techo content >file &&\n \tgit add file &&\n \tgit commit -m \"added sub and file\" &&\n+\tmkdir -p deep/directory/hierachy &&\n+\tgit submodule add ./. deep/directory/hierachy/sub &&\n+\tgit commit -m \"added another submodule\" &&\n \tgit branch submodule\n '\n \n@@ -475,4 +478,17 @@ test_expect_success 'mv -k does not accidentally destroy submodules' '\n \tgit checkout .\n '\n \n+test_expect_success 'moving a submodule in nested directories' '\n+\t(\n+\t\tcd deep &&\n+\t\tgit mv directory ../ &&\n+\t\t# git status would fail if the update of linking git dir to\n+\t\t# work dir of the submodule failed.\n+\t\tgit status &&\n+\t\tgit config -f ../.gitmodules submodule.deep/directory/hierachy/sub.path >../actual &&\n+\t\techo \"directory/hierachy/sub\" >../expect\n+\t) &&\n+\ttest_cmp actual expect\n+'\n+\n test_done\n-- \n2.6.6.dirty\n"}]}