{"thread":{"id":"42033","subject":"'git mv' doesn't move submodule if it's in a subdirectory","startedAt":"2016-04-15T08:14:11Z","lastAt":"2016-04-15T19:39:39Z","messageCount":7,"participants":["Albin Otterhäll","Stefan Beller","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"283522","messageId":"5710A2D3.8090003@otterhall.com","threadId":"42033","inReplyTo":null,"subject":"'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Albin Otterhäll","fromEmail":"gmane@otterhall.com","sentAt":"2016-04-15T08:14:11Z","receivedAt":"2016-04-15T08:14:11Z","isPatch":false,"sender":{"key":"gmane@otterhall.com","avatar":null},"body":"I've a submodule located in a subdirectory\n({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole\ndirectory up a level ({git_rep}/{directory}/{submodule}). But when I\nused 'git mv {directory} ../' the '.gitmodule' file didn't get modified.\n\nBest regards,\nAlbin Otterhäll\n"},{"id":"283546","messageId":"CAGZ79kaN-s74cJkgOq3+7e57-BKevMr8pr=tAHVEpELetVYnTA@mail.gmail.com","threadId":"42033","inReplyTo":"5710A2D3.8090003@otterhall.com","subject":"Re: 'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-15T17:18:24Z","receivedAt":"2016-04-15T17:18:24Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:\n> I've a submodule located in a subdirectory\n> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole\n> directory up a level ({git_rep}/{directory}/{submodule}). But when I\n> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.\n>\n> Best regards,\n> Albin Otterhäll\n\nThanks for the bug report!\nWhich version of Git do you use? (Did you try different versions?)\n"},{"id":"283553","messageId":"CAGZ79kZifiEY1rg6KNFRnkOemjJhY9fFpxHmK0gB8fLh1siAxw@mail.gmail.com","threadId":"42033","inReplyTo":"CAGZ79kaN-s74cJkgOq3+7e57-BKevMr8pr=tAHVEpELetVYnTA@mail.gmail.com","subject":"Re: 'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-15T17:59:46Z","receivedAt":"2016-04-15T17:59:46Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Apr 15, 2016 at 10:18 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:\n>> I've a submodule located in a subdirectory\n>> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole\n>> directory up a level ({git_rep}/{directory}/{submodule}). But when I\n>> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.\n>>\n>> Best regards,\n>> Albin Otterhäll\n>\n> Thanks for the bug report!\n> Which version of Git do you use? (Did you try different versions?)\n\nI think I can reproduce the problem. A regression test (which currently fails)\ncould look like\ndiff --git a/t/t7001-mv.sh b/t/t7001-mv.sh\nindex 4008fae..3b96a9a 100755\n--- a/t/t7001-mv.sh\n+++ b/t/t7001-mv.sh\n@@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '\n        echo content >file &&\n        git add file &&\n        git commit -m \"added sub and file\" &&\n+       mkdir -p deep/directory/hierachy &&\n+       git submodule add ./. deep/directory/hierachy/sub &&\n+       git commit -m \"added another submodule\" &&\n        git branch submodule\n '\n\n@@ -475,4 +478,14 @@ test_expect_success 'mv -k does not accidentally\ndestroy submodules' '\n        git checkout .\n '\n\n+test_expect_failure 'moving a submodule in nested directories' '\n+       (\n+               cd deep &&\n+               git mv directory ../ &&\n+               git status\n+               # currently git status exits with 128\n+               # fatal: Not a git repository:\ndirectory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub\n+       )\n+'\n+\n test_done\n"},{"id":"283554","messageId":"xmqqlh4ebumv.fsf@gitster.mtv.corp.google.com","threadId":"42033","inReplyTo":"CAGZ79kZifiEY1rg6KNFRnkOemjJhY9fFpxHmK0gB8fLh1siAxw@mail.gmail.com","subject":"Re: 'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-15T18:21:28Z","receivedAt":"2016-04-15T18:21:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> I think I can reproduce the problem. A regression test (which currently fails)\n> could look like\n\nThanks.  I however do not think this is a regression.\n\nChanges around 0656781f (mv: update the path entry in .gitmodules\nfor moved submodules, 2013-08-06) did introduce \"git mv dir1 dir2\"\nwhen 'dir1' is a submodule, but I do not think it went beyond that.\nI do not see any effort to treat a submodule that is discovered by\nscanning a directory that was given from the command line,\ni.e. prepare_move_submodule() is not called for them, and the\nentries in the submodule_gitfile[] array that correspond to them are\nexplicitly set to NULL in the loop.\n\n\n> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh\n> index 4008fae..3b96a9a 100755\n> --- a/t/t7001-mv.sh\n> +++ b/t/t7001-mv.sh\n> @@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '\n>         echo content >file &&\n>         git add file &&\n>         git commit -m \"added sub and file\" &&\n> +       mkdir -p deep/directory/hierachy &&\n> +       git submodule add ./. deep/directory/hierachy/sub &&\n> +       git commit -m \"added another submodule\" &&\n>         git branch submodule\n>  '\n>\n> @@ -475,4 +478,14 @@ test_expect_success 'mv -k does not accidentally\n> destroy submodules' '\n>         git checkout .\n>  '\n>\n> +test_expect_failure 'moving a submodule in nested directories' '\n> +       (\n> +               cd deep &&\n> +               git mv directory ../ &&\n> +               git status\n> +               # currently git status exits with 128\n> +               # fatal: Not a git repository:\n> directory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub\n> +       )\n> +'\n> +\n>  test_done\n"},{"id":"283555","messageId":"CAGZ79kajE-R84=dSpBBFttwwDg4DbF59gnmzaN-C2w6U3rFwVw@mail.gmail.com","threadId":"42033","inReplyTo":"xmqqlh4ebumv.fsf@gitster.mtv.corp.google.com","subject":"Re: 'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-15T18:24:56Z","receivedAt":"2016-04-15T18:24:56Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Apr 15, 2016 at 11:21 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> I think I can reproduce the problem. A regression test (which currently fails)\n>> could look like\n>\n> Thanks.  I however do not think this is a regression.\n>\n> Changes around 0656781f (mv: update the path entry in .gitmodules\n> for moved submodules, 2013-08-06) did introduce \"git mv dir1 dir2\"\n> when 'dir1' is a submodule, but I do not think it went beyond that.\n> I do not see any effort to treat a submodule that is discovered by\n> scanning a directory that was given from the command line,\n> i.e. prepare_move_submodule() is not called for them, and the\n> entries in the submodule_gitfile[] array that correspond to them are\n> explicitly set to NULL in the loop.\n\nAlso I just realize this is not exactly the same bug as reported.\nAlbin complains about the .gitmodules file not being adjusted, whereas\nthe test case I wrote breaks commands in your superproject, i.e. `git status`\nor `git diff` just dies.\n\n(Manually inspecting the .gitmodules file turns out it is not adjusted as well.)\n\n>\n>\n>> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh\n>> index 4008fae..3b96a9a 100755\n>> --- a/t/t7001-mv.sh\n>> +++ b/t/t7001-mv.sh\n>> @@ -292,6 +292,9 @@ test_expect_success 'setup submodule' '\n>>         echo content >file &&\n>>         git add file &&\n>>         git commit -m \"added sub and file\" &&\n>> +       mkdir -p deep/directory/hierachy &&\n>> +       git submodule add ./. deep/directory/hierachy/sub &&\n>> +       git commit -m \"added another submodule\" &&\n>>         git branch submodule\n>>  '\n>>\n>> @@ -475,4 +478,14 @@ test_expect_success 'mv -k does not accidentally\n>> destroy submodules' '\n>>         git checkout .\n>>  '\n>>\n>> +test_expect_failure 'moving a submodule in nested directories' '\n>> +       (\n>> +               cd deep &&\n>> +               git mv directory ../ &&\n>> +               git status\n>> +               # currently git status exits with 128\n>> +               # fatal: Not a git repository:\n>> directory/hierachy/sub/../../../../.git/modules/deep/directory/hierachy/sub\n>> +       )\n>> +'\n>> +\n>>  test_done\n"},{"id":"283561","messageId":"1460747492-6640-1-git-send-email-sbeller@google.com","threadId":"42033","inReplyTo":"CAGZ79kajE-R84=dSpBBFttwwDg4DbF59gnmzaN-C2w6U3rFwVw@mail.gmail.com","subject":"[PATCH] mv: allow moving nested submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-15T19:11:32Z","receivedAt":"2016-04-15T19:11:32Z","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\nAlbin,\nI think this would fix your problem.\n\nDeveloped on origin/master (it may apply on older versions, though I did not test)\n\nThanks,\nStefan\n\n builtin/mv.c  |  7 +++++--\n t/t7001-mv.sh | 16 ++++++++++++++++\n 2 files changed, 21 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex aeae855..65fff11 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -252,9 +252,12 @@ 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\tif (!show_only) {\n+\t\t\tif (mode != INDEX &&\n+\t\t\t    rename(src, dst) < 0 &&\n+\t\t\t    !ignore_errors)\n \t\t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n+\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]);\ndiff --git a/t/t7001-mv.sh b/t/t7001-mv.sh\nindex 4008fae..4a2570e 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.8.1.211.g630c034\n"},{"id":"283570","messageId":"nerg27$t94$1@ger.gmane.org","threadId":"42033","inReplyTo":"CAGZ79kaN-s74cJkgOq3+7e57-BKevMr8pr=tAHVEpELetVYnTA@mail.gmail.com","subject":"Re: 'git mv' doesn't move submodule if it's in a subdirectory","fromName":"Albin Otterhäll","fromEmail":"gmane@otterhall.com","sentAt":"2016-04-15T19:39:39Z","receivedAt":"2016-04-15T19:39:39Z","isPatch":false,"sender":{"key":"gmane@otterhall.com","avatar":null},"body":"On 2016-04-15 19:18, Stefan Beller wrote:\n> On Fri, Apr 15, 2016 at 1:14 AM, Albin Otterhäll <gmane@otterhall.com> wrote:\n>> I've a submodule located in a subdirectory\n>> ({git_rep}/home/{directory}/{submodule}), and I wanted to move the whole\n>> directory up a level ({git_rep}/{directory}/{submodule}). But when I\n>> used 'git mv {directory} ../' the '.gitmodule' file didn't get modified.\n>>\n>> Best regards,\n>> Albin Otterhäll\n> \n> Thanks for the bug report!\n> Which version of Git do you use? (Did you try different versions?)\n> \n\nI'm using 2.8.0 (on an Arch system). Haven't tested on any other version.\n"}]}