git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git submodule update remote keeps using previous default branch
@ 2021-10-15  8:34 Sjoerd Langkemper
  2021-10-15  9:05 ` Bryan Turner
  2021-10-15 10:45 ` Sjoerd Langkemper
  0 siblings, 2 replies; 3+ messages in thread
From: Sjoerd Langkemper @ 2021-10-15  8:34 UTC (permalink / raw)
  To: git

I am having trouble with git 2.33.1 checking out the wrong branch for
submodules for which the default branch has changed. `git submodule
update --remote` seems to remember the branch name to retrieve, while
I expect it to use the remote HEAD every time. This causes unexpected
behaviour when the remote HEAD starts pointing to another branch.

I create a new git project and add a submodule, with `git submodule
add git@host:foo/testproject.git`.

This checks out the default branch, `master` in this case. `git remote
show origin` also shows that `master` is the HEAD branch. Running `git
submodule update --remote` updates the submodule to the latest master.

Now I change the default branch on the remote (using Gitlab's web
interface) to `newmaster`.

`git remote show origin` now correctly shows `newmaster` as the
remote's HEAD branch. However, running `git submodule update --remote`
still updates the submodule to the latest `master` branch, while I
expect it to update to the lastest `newmaster` branch.

There's no branch specified in .gitmodules or .git/config. I am not
sure how git remembers the branch. When switching `testproject` to
`newmaster` manually and then running `git submodule update --remote`,
it is reset to `master` again.

Is this a bug? Can I change the branch somehow?

Regards,

Sjoerd Langkemper

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git submodule update remote keeps using previous default branch
  2021-10-15  8:34 Git submodule update remote keeps using previous default branch Sjoerd Langkemper
@ 2021-10-15  9:05 ` Bryan Turner
  2021-10-15 10:45 ` Sjoerd Langkemper
  1 sibling, 0 replies; 3+ messages in thread
From: Bryan Turner @ 2021-10-15  9:05 UTC (permalink / raw)
  To: Sjoerd Langkemper; +Cc: Git Users

On Fri, Oct 15, 2021 at 1:35 AM Sjoerd Langkemper
<sjoerd-2021@linuxonly.nl> wrote:
>
> I am having trouble with git 2.33.1 checking out the wrong branch for
> submodules for which the default branch has changed. `git submodule
> update --remote` seems to remember the branch name to retrieve, while
> I expect it to use the remote HEAD every time. This causes unexpected
> behaviour when the remote HEAD starts pointing to another branch.
>
> I create a new git project and add a submodule, with `git submodule
> add git@host:foo/testproject.git`.
>
> This checks out the default branch, `master` in this case. `git remote
> show origin` also shows that `master` is the HEAD branch. Running `git
> submodule update --remote` updates the submodule to the latest master.
>
> Now I change the default branch on the remote (using Gitlab's web
> interface) to `newmaster`.
>
> `git remote show origin` now correctly shows `newmaster` as the
> remote's HEAD branch. However, running `git submodule update --remote`
> still updates the submodule to the latest `master` branch, while I
> expect it to update to the lastest `newmaster` branch.

I suspect this is going to be the same answer I gave on the last
thread about submodules[1]. Submodules in Git store the _commit ID_
they point to in the tree, but they do not store a _ref name_, nor do
they have some indicator for "It was the default branch". They choose
a ref by (essentially) looping over the refs from the remote (which
are always sent in alphabetical order) and choosing the first one with
a matching SHA. If your "newmaster" is alphabetically after "master",
and "master" still exists, and both refs point to the same commit (or
only "master" points to it), I suspect your submodule is going to
choose that.

[1] https://lore.kernel.org/git/CAGyf7-FAHJOb6iQYqYNt0WSk+zUHUJ_FjrU1xis1bBQd9Z6KPQ@mail.gmail.com/

>
> There's no branch specified in .gitmodules or .git/config. I am not
> sure how git remembers the branch. When switching `testproject` to
> `newmaster` manually and then running `git submodule update --remote`,
> it is reset to `master` again.
>
> Is this a bug? Can I change the branch somehow?

If you updated the submodule to reference a commit that was on
"newmaster" and not present on "master", I think it'd change.

>
> Regards,
>
> Sjoerd Langkemper

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git submodule update remote keeps using previous default branch
  2021-10-15  8:34 Git submodule update remote keeps using previous default branch Sjoerd Langkemper
  2021-10-15  9:05 ` Bryan Turner
@ 2021-10-15 10:45 ` Sjoerd Langkemper
  1 sibling, 0 replies; 3+ messages in thread
From: Sjoerd Langkemper @ 2021-10-15 10:45 UTC (permalink / raw)
  To: git

The submodule is updated according to where `origin/HEAD` points. The
`origin/HEAD` ref of a repository is not automatically updated when
the upstream default branch changes. However, this can be forced with
`git remote set-head origin -a`.

I think it is a little bit surprising that `origin/HEAD` does not
necessarily point to the remote default branch. However, changing the
default branch should be pretty rare, so I understand this is not
checked every time.

Regards,

Sjoerd Langkemper

On Fri, Oct 15, 2021 at 10:34 AM Sjoerd Langkemper
<sjoerd-2021@linuxonly.nl> wrote:
>
> I am having trouble with git 2.33.1 checking out the wrong branch for
> submodules for which the default branch has changed. `git submodule
> update --remote` seems to remember the branch name to retrieve, while
> I expect it to use the remote HEAD every time. This causes unexpected
> behaviour when the remote HEAD starts pointing to another branch.
>
> I create a new git project and add a submodule, with `git submodule
> add git@host:foo/testproject.git`.
>
> This checks out the default branch, `master` in this case. `git remote
> show origin` also shows that `master` is the HEAD branch. Running `git
> submodule update --remote` updates the submodule to the latest master.
>
> Now I change the default branch on the remote (using Gitlab's web
> interface) to `newmaster`.
>
> `git remote show origin` now correctly shows `newmaster` as the
> remote's HEAD branch. However, running `git submodule update --remote`
> still updates the submodule to the latest `master` branch, while I
> expect it to update to the lastest `newmaster` branch.
>
> There's no branch specified in .gitmodules or .git/config. I am not
> sure how git remembers the branch. When switching `testproject` to
> `newmaster` manually and then running `git submodule update --remote`,
> it is reset to `master` again.
>
> Is this a bug? Can I change the branch somehow?
>
> Regards,
>
> Sjoerd Langkemper

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-15 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  8:34 Git submodule update remote keeps using previous default branch Sjoerd Langkemper
2021-10-15  9:05 ` Bryan Turner
2021-10-15 10:45 ` Sjoerd Langkemper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).