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

Re: Bug in git submodule update --remote

From
Atharva Raykar <raykar.ath@gmail.com>
Date
May 19, 2021, 10:49 UTC
Message-ID
<EB55447C-538F-44DE-BFC0-A3BD1A970E99@gmail.com>
In-Reply-To
<c4b27662-1228-a1ff-26fc-637897ffc8e7@riscosopen.org>
On 14-May-2021, at 23:41, Ben Avison <bavison@riscosopen.org> wrote:
Show 12 quoted lines
> 
> What's going on is that within "git submodule update --remote", the sha1 used is formed by looking up the submodule's ref "<remote>/<branch>". The change in git 2.27.1 is that if no remote tracking branch is stated in the superproject's .gitmodules file, <branch> defaults to "HEAD" rather than "master" as previously. That's fine if <remote> is "origin", but in practice, it depends on how the submodule is currently checked out:
> 
> * if it's in detached HEAD state, <remote> is set to "origin"
> * if its branch is not a tracking branch, "origin" is also used
> * but if it's a tracking branch (as I used in my workflow above - not uncommon in pull request workflows because you might grant other people access to the branch during the review process) then it looks up the name of the remote which is being tracked
> 
> First observation: a ref called "myfork/HEAD" presumably *could* have been created by the "git remote add" command, reflecting that remote's default branch. Should it?
> 
> In practice, that's not actually what I'd want, though. If I do "git submodule update --remote", I personally normally do so as a shortcut compared to cloning everything again. I don't expect the behaviour to change depending on whether I happen to have left one of the submodules checked out on a tracking branch or not: myfork/master is potentially quite out of date compared to origin/master.
> 
> It also makes very little sense to me that issuing "git submodule update --remote" twice in quick succession would leave us in a different state, because the first call puts all the submodules into detached HEAD state, meaning that the second call always looks up the remote tracking branches from the submodule's "origin" remote.

I agree with you, this behaviour is rather inconsistent, and can be quite surprising to an unsuspecting user.

Show 5 quoted lines
> One way this could be fixed is that if <branch> turns out to be "HEAD", we could force <remote> to be "origin". However, this doesn't address the equivalent problem that arises if the remote tracking branch *is* named in .gitmodules.
> 
> I'd therefore like to propose that "git submodule update --remote" *always* uses the remote named "origin" to form the ref used to check out the submodule. However, I'm not sure whether everyone would agree that this constitutes a bugfix, or whether I'd need to introduce a new switch to enforce this behaviour.
> 
> So, what do you think?

If I understood you correctly, you'd prefer that the updating of the submodule should be independent of the ref that is checked out in the submodule's directory.

While I am not sure of the reason why the design of 'update --remote' uses the remote-tracking branch of the submodule, I can imagine adding a switch like 'submodule.<name>.remote' that defaults to 'origin'. Then the behaviour could be changed such that it always pulls from the remote specified in that option.

This would help make the behaviour consistent in all the cases you mentioned, while also giving the option for a user to update the submodule from the remote of their choice (which may not be origin).

-- Atharva Raykar

Previous: Ben AvisonNext: Ben Avison
Message 2 of 8 in “Bug in git submodule update --remote”
  1. Ben AvisonMay 14, 2021
  2. Atharva RaykarMay 19, 2021
  3. Ben AvisonMay 19, 2021
  4. Atharva RaykarMay 21, 2021
  5. Christian CouderMay 21, 2021
  6. Philippe BlainMay 22, 2021
  7. Atharva RaykarMay 19, 2021
  8. Philippe BlainMay 22, 2021

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.