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

[BUG] Changing remote URL of "deinited" submodule not taken into account

From
NBNicolás Ojeda Bär <n.oje.bar@gmail.com>
Date
Nov 30, 2024, 07:48 UTC
Message-ID
<CAPunWhBQcAifapqxyq7nY+S5WWhZQhBKgeYLL56U1ewRCa7QDA@mail.gmail.com>

Recently I came across an issue involving Git submodules which seems like a bug to me.

In short (precise reproduction instructions below), if one updates the remote URL of a submodule while it is "deinited", the next time one calls "git update" the old URL will be used instead of the new one.

Here is how to reproduce the issue synthetically (in a fresh directory):
  git init
  git submodule add https://github.com/git/git-reference sub # random repo
  git commit -m "add submodule"
  git submodule deinit sub
  git submodule init

At this point, the remote URL of the submodule has been copied to .git/config. We change it:

  git config submodule.sub.url "new-url"

Now we checkout the submodule. I am expecting to use "new-url" as remote URL in the checkout.

  git submodule update sub
However, the old URL is used:
  git -C sub config remote.origin.url # => old URL instead of "new-url"

The problem seems to be that the clone at .git/modules/sub does not have its remote URL updated when being "inited" after a remote URL change while it was "deinited".

Currently I am working around this issue in scripts by doing:
  if [ -f .git/modules/$sm_name/config ]
  then
    git config -f .git/modules/$sm_name/config remote.origin.url $(git
config submodule.$sm_name.url)
  fi
Any insight would be appreciated. Thanks!

Cheers, Nicolas

Next: Kristoffer Haugsbakk
Message 1 of 3 in “[BUG] Changing remote URL of "deinited" submodule not taken into account”
  1. Nicolás Ojeda BärNov 30, 2024
  2. Kristoffer HaugsbakkNov 30, 2024
  3. Nicolás Ojeda BärNov 30, 2024

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.