git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: merge branch with updated submodule leaves repo in modified state

From
Elijah Newren <newren@gmail.com>
Date
Dec 11, 2019, 00:51 UTC
Message-ID
<CABPp-BEhZaUxb2qKQLEpkG7+a9zQhYMxmbc=Na+P_RetrWk+1Q@mail.gmail.com>
In-Reply-To
<20191210194803.emsvjibq3jyjkjrx@t440s>
On Tue, Dec 10, 2019 at 11:58 AM Daniel Bosk <dbosk@kth.se> wrote:
Show 72 quoted lines
>
> Hi all!
>
> `git merge`: if a submodule is updated in the merged branch, the new
> version is not checked out after the merge. Is this correct behaviour?
>
> `git switch` correctly updates the submodules when switching between the
> branches. I would expect `git merge` to leave the things in the most
> up-to-date state.
>
> I tested this with the following settings.
>
>   $ git version
>   git version 2.24.0
>
>   $ git config -l
>   push.default=matching
>   diff.submodule=log
>   diff.colorwords=true
>   diff.algorithm=minimal
>   diff.exit-code=true
>   commit.gpgsign=true
>   submodule.fetchjobs=0
>   submodule.recurse=true
>   log.follow=true
>
> MWE:
>
> ```
> mkdir repoA repoB
>
> # init repos with READMEs
> cd repoA
> git init
> echo "A" > README
> git add README
> git commit -m "Adds repoA README" README
>
> cd ../repoB
> git init
> echo "B" > README
> git add README
> git commit -m "Adds repoB README" README
>
> # construct nested structure: repoA/repoB
> cd ../repoA
> git submodule add ../repoB/.git
> git commit -m "Adds repoB submodule"
>
> # update repoB in branch
> git switch -c update-repoB-submodule
> cd repoB
> echo "B updated" > README
> git commit -m "Updates repoB README" README
> cd ..
> git commit -m "Updates repoB submodule" repoB
> ```
>
> Now, doing `git switch master` will have the correct version of repoB,
> where `cat repoB/README` outputs "B". A `git switch update-repoB-submodule`
> from there will yield `cat repoB/README` output "B updated".
>
> However, switching to master and then merging will leave repoB at the
> old commit:
> ```
> git switch master
> git merge update-repoB-submodule
> ```
> A `git status` says there are new commits in repoB, it's actually a
> rewind which excludes the new commit (changing `repoB/README`), so `cat
> repoB/README` outputs "B" instead of "B updated". It feels unintended to
> get a repo which is in a modified state after a clean merge. Bug?

Don't know where it falls on the spectrum from bug to unimplemented feature, but it's certainly a known issue. The last time I remember discussing this was here:

https://lore.kernel.org/git/CABPp-BHDrw_dAESic3xK7kC3jMgKeNQuPQF69OpbVYhRkbhJsw@mail.gmail.com/

Hope that helps, Elijah

Previous: Daniel BoskNext: Daniel Bosk
Message 2 of 3 in “merge branch with updated submodule leaves repo in modified state”
  1. Daniel BoskDec 10, 2019
  2. Elijah NewrenDec 11, 2019
  3. Daniel BoskDec 11, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.