{"thread":{"id":"52424","subject":"merge branch with updated submodule leaves repo in modified state","startedAt":"2019-12-10T19:56:12Z","lastAt":"2019-12-11T09:14:27Z","messageCount":3,"participants":["Daniel Bosk","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387904","messageId":"20191210194803.emsvjibq3jyjkjrx@t440s","threadId":"52424","inReplyTo":null,"subject":"merge branch with updated submodule leaves repo in modified state","fromName":"Daniel Bosk","fromEmail":"dbosk@kth.se","sentAt":"2019-12-10T19:48:03Z","receivedAt":"2019-12-10T19:56:12Z","isPatch":false,"sender":{"key":"dbosk@kth.se","avatar":null},"body":"Hi all!\n\n`git merge`: if a submodule is updated in the merged branch, the new \nversion is not checked out after the merge. Is this correct behaviour?\n\n`git switch` correctly updates the submodules when switching between the \nbranches. I would expect `git merge` to leave the things in the most \nup-to-date state.\n\nI tested this with the following settings.\n\n  $ git version\n  git version 2.24.0\n\n  $ git config -l\n  push.default=matching\n  diff.submodule=log\n  diff.colorwords=true\n  diff.algorithm=minimal\n  diff.exit-code=true\n  commit.gpgsign=true\n  submodule.fetchjobs=0\n  submodule.recurse=true\n  log.follow=true\n   \nMWE:\n\n```\nmkdir repoA repoB\n\n# init repos with READMEs\ncd repoA\ngit init\necho \"A\" > README\ngit add README\ngit commit -m \"Adds repoA README\" README\n\ncd ../repoB\ngit init\necho \"B\" > README\ngit add README\ngit commit -m \"Adds repoB README\" README\n\n# construct nested structure: repoA/repoB\ncd ../repoA\ngit submodule add ../repoB/.git\ngit commit -m \"Adds repoB submodule\"\n\n# update repoB in branch\ngit switch -c update-repoB-submodule\ncd repoB\necho \"B updated\" > README\ngit commit -m \"Updates repoB README\" README\ncd ..\ngit commit -m \"Updates repoB submodule\" repoB\n```\n\nNow, doing `git switch master` will have the correct version of repoB, \nwhere `cat repoB/README` outputs \"B\". A `git switch update-repoB-submodule`\nfrom there will yield `cat repoB/README` output \"B updated\".\n\nHowever, switching to master and then merging will leave repoB at the \nold commit:\n```\ngit switch master\ngit merge update-repoB-submodule\n```\nA `git status` says there are new commits in repoB, it's actually a \nrewind which excludes the new commit (changing `repoB/README`), so `cat \nrepoB/README` outputs \"B\" instead of \"B updated\". It feels unintended to \nget a repo which is in a modified state after a clean merge. Bug?\n\nCheers,\nDaniel\n"},{"id":"387926","messageId":"CABPp-BEhZaUxb2qKQLEpkG7+a9zQhYMxmbc=Na+P_RetrWk+1Q@mail.gmail.com","threadId":"52424","inReplyTo":"20191210194803.emsvjibq3jyjkjrx@t440s","subject":"Re: merge branch with updated submodule leaves repo in modified state","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-11T00:51:46Z","receivedAt":"2019-12-11T00:52:01Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Tue, Dec 10, 2019 at 11:58 AM Daniel Bosk <dbosk@kth.se> wrote:\n>\n> Hi all!\n>\n> `git merge`: if a submodule is updated in the merged branch, the new\n> version is not checked out after the merge. Is this correct behaviour?\n>\n> `git switch` correctly updates the submodules when switching between the\n> branches. I would expect `git merge` to leave the things in the most\n> up-to-date state.\n>\n> I tested this with the following settings.\n>\n>   $ git version\n>   git version 2.24.0\n>\n>   $ git config -l\n>   push.default=matching\n>   diff.submodule=log\n>   diff.colorwords=true\n>   diff.algorithm=minimal\n>   diff.exit-code=true\n>   commit.gpgsign=true\n>   submodule.fetchjobs=0\n>   submodule.recurse=true\n>   log.follow=true\n>\n> MWE:\n>\n> ```\n> mkdir repoA repoB\n>\n> # init repos with READMEs\n> cd repoA\n> git init\n> echo \"A\" > README\n> git add README\n> git commit -m \"Adds repoA README\" README\n>\n> cd ../repoB\n> git init\n> echo \"B\" > README\n> git add README\n> git commit -m \"Adds repoB README\" README\n>\n> # construct nested structure: repoA/repoB\n> cd ../repoA\n> git submodule add ../repoB/.git\n> git commit -m \"Adds repoB submodule\"\n>\n> # update repoB in branch\n> git switch -c update-repoB-submodule\n> cd repoB\n> echo \"B updated\" > README\n> git commit -m \"Updates repoB README\" README\n> cd ..\n> git commit -m \"Updates repoB submodule\" repoB\n> ```\n>\n> Now, doing `git switch master` will have the correct version of repoB,\n> where `cat repoB/README` outputs \"B\". A `git switch update-repoB-submodule`\n> from there will yield `cat repoB/README` output \"B updated\".\n>\n> However, switching to master and then merging will leave repoB at the\n> old commit:\n> ```\n> git switch master\n> git merge update-repoB-submodule\n> ```\n> A `git status` says there are new commits in repoB, it's actually a\n> rewind which excludes the new commit (changing `repoB/README`), so `cat\n> repoB/README` outputs \"B\" instead of \"B updated\". It feels unintended to\n> get a repo which is in a modified state after a clean merge. Bug?\n\nDon't know where it falls on the spectrum from bug to unimplemented\nfeature, but it's certainly a known issue.  The last time I remember\ndiscussing this was here:\n\nhttps://lore.kernel.org/git/CABPp-BHDrw_dAESic3xK7kC3jMgKeNQuPQF69OpbVYhRkbhJsw@mail.gmail.com/\n\n\nHope that helps,\nElijah\n"},{"id":"387932","messageId":"20191211091419.n4uhqq7nfafqds2i@t440s","threadId":"52424","inReplyTo":"CABPp-BEhZaUxb2qKQLEpkG7+a9zQhYMxmbc=Na+P_RetrWk+1Q@mail.gmail.com","subject":"Re: merge branch with updated submodule leaves repo in modified state","fromName":"Daniel Bosk","fromEmail":"dbosk@kth.se","sentAt":"2019-12-11T09:14:19Z","receivedAt":"2019-12-11T09:14:27Z","isPatch":false,"sender":{"key":"dbosk@kth.se","avatar":null},"body":"On Tue 10 Dec 2019 16:51:46 GMT, Elijah Newren wrote:\n> Don't know where it falls on the spectrum from bug to unimplemented\n> feature, but it's certainly a known issue.  The last time I remember\n> discussing this was here:\n> \n> https://lore.kernel.org/git/CABPp-BHDrw_dAESic3xK7kC3jMgKeNQuPQF69OpbVYhRkbhJsw@mail.gmail.com/\n> \n> \n> Hope that helps,\n\nDefinitely, thanks a lot for the pointer!\n\n          Daniel\n"}]}