{"thread":{"id":"45615","subject":"[BUG?] Issue with merging from another branch after replacing subdirectory with submodule","startedAt":"2017-04-06T06:13:12Z","lastAt":"2017-04-07T15:26:10Z","messageCount":3,"participants":["Ben Nason","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"316257","messageId":"CAA-fqg2EwfMQ-KoAMHDFca1c7jpQgihhqsLejEK3Zs8O1D4DLg@mail.gmail.com","threadId":"45615","inReplyTo":null,"subject":"[BUG?] Issue with merging from another branch after replacing subdirectory with submodule","fromName":"Ben Nason","fromEmail":"bnason@netflix.com","sentAt":"2017-04-06T06:10:02Z","receivedAt":"2017-04-06T06:13:12Z","isPatch":false,"sender":{"key":"bnason@netflix.com","avatar":null},"body":"Hi,\n\nIn git if you replace a subdirectory with a submodule in one branch,\nevery successive merge from another branch without that change will\ncause a conflict. To reproduce this please see below (DOS batch file).\n\nIs this expected behavior?\n\nThanks,\nBenbuck\n\n:: prep simple repo with subdir\ngit init repo\npushd repo\necho foo > foo.txt\ngit add --all\ngit commit -m \"foo\"\nmkdir sub\necho bar > sub\\bar.txt\ngit add --all\ngit commit -m \"bar\"\npopd\n\n:: prep simple submodule\ngit init submod\npushd submod\necho baz2 > baz.txt\ngit add --all\ngit commit -m \"baz2\"\npopd\n\n:: in a new branch: delete subdir, replace with submodule\npushd repo\ngit checkout -b resub\ngit rm -rf sub\ngit commit -m \"delete subdir\"\ngit submodule add ../submod sub\ngit submodule update --init\ngit commit -m \"add submod\"\n\n:: in old branch: make an unrelated change\ngit checkout master\ngit clean -fd\ngit rs --hard master\necho foo2 > foo.txt\ngit commit --all -m \"foo2\"\n\n:: switch back to new branch\ngit checkout resub\ngit rs --hard resub\ngit submodule update --init\npushd sub\ngit reset --hard master\npopd\n\n:: all is good so far, now merge\ngit merge master\ngit status\n@echo !!!!!! note the above merge conflict !!!!!!\npause\n:: resolve the conflict to keep the submodule\ngit reset sub\ngit commit --no-edit\n\n\n:: make another change to old branch\ngit checkout master\ngit clean -fd\ngit rs --hard master\necho foo3 > foo.txt\ngit commit --all -m \"foo3\"\ngit checkout resub\ngit rs --hard resub\ngit submodule update --init\npushd sub\ngit reset --hard master\npopd\n\n:: merge again\ngit merge master\ngit status\n@echo !!!!!! note that the conflict happens on every single merge !!!!!!\npause\n\npopd\n"},{"id":"316313","messageId":"CAGZ79kaGQHvGv-ZpfppbATucrJWVdS8Lq33CKs5AbV7qDGE3BA@mail.gmail.com","threadId":"45615","inReplyTo":"CAA-fqg2EwfMQ-KoAMHDFca1c7jpQgihhqsLejEK3Zs8O1D4DLg@mail.gmail.com","subject":"Re: [BUG?] Issue with merging from another branch after replacing subdirectory with submodule","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-04-06T23:05:19Z","receivedAt":"2017-04-06T23:05:27Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Apr 5, 2017 at 11:10 PM, Ben Nason <bnason@netflix.com> wrote:\n> Hi,\n>\n> In git if you replace a subdirectory with a submodule in one branch,\n> every successive merge from another branch without that change will\n> cause a conflict. To reproduce this please see below (DOS batch file).\n>\n> Is this expected behavior?\n\nYes.\n\n\"git submodule update [--init]\" only (creates or) updates existing\nsubmodules. It doesn't take care of removing submodules that are\nno longer recorded in the tree.\n\n\"git merge\" currently also does not touch submodules. (we may have\ngit merge --recurse-submodules soon, though). So as soon as there\nis a conflict between the submodule (or an unrelated repo, who happens\nto live inside this other repo), and new directories/files that would appear,\nthe merge errors out.\n\nIdeally Git would be smarter than the current behavior.\n\nStefan\n"},{"id":"316359","messageId":"CAA-fqg1DGUmdXEAnYfEuK2Wts2wLfEr2hhharAghbCexL1+yAw@mail.gmail.com","threadId":"45615","inReplyTo":"CAGZ79kaGQHvGv-ZpfppbATucrJWVdS8Lq33CKs5AbV7qDGE3BA@mail.gmail.com","subject":"Re: [BUG?] Issue with merging from another branch after replacing subdirectory with submodule","fromName":"Ben Nason","fromEmail":"bnason@netflix.com","sentAt":"2017-04-07T15:25:41Z","receivedAt":"2017-04-07T15:26:10Z","isPatch":false,"sender":{"key":"bnason@netflix.com","avatar":null},"body":"Hi Stefan,\n\nThanks for the reply. Is there any known workaround for this\nsituation, so that a manual resolve isn't needed for every single\nmerge in this scenario?\n\nThanks,\nBenbuck\n\n\nOn Thu, Apr 6, 2017 at 4:05 PM, Stefan Beller <sbeller@google.com> wrote:\n> On Wed, Apr 5, 2017 at 11:10 PM, Ben Nason <bnason@netflix.com> wrote:\n>> Hi,\n>>\n>> In git if you replace a subdirectory with a submodule in one branch,\n>> every successive merge from another branch without that change will\n>> cause a conflict. To reproduce this please see below (DOS batch file).\n>>\n>> Is this expected behavior?\n>\n> Yes.\n>\n> \"git submodule update [--init]\" only (creates or) updates existing\n> submodules. It doesn't take care of removing submodules that are\n> no longer recorded in the tree.\n>\n> \"git merge\" currently also does not touch submodules. (we may have\n> git merge --recurse-submodules soon, though). So as soon as there\n> is a conflict between the submodule (or an unrelated repo, who happens\n> to live inside this other repo), and new directories/files that would appear,\n> the merge errors out.\n>\n> Ideally Git would be smarter than the current behavior.\n>\n> Stefan\n"}]}