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

Re: Error fetching submodule from submodule

From
Jeff King <peff@peff.net>
Date
Mar 7, 2019, 18:08 UTC
Message-ID
<20190307180831.GA21404@sigill.intra.peff.net>
In-Reply-To
<CAL-rKu6AcyHdrCsVikwQxTgKHgtV86+BeHOv_sTSu-jvwME75Q@mail.gmail.com>
On Thu, Mar 07, 2019 at 12:07:21PM +0100, Jesper Rønn-Jensen wrote:
> Hi I think I may have found an error in the way git handles a
> submodule's submodule. Read further for the example (extracted from a
> real project).

First off, thank you for the example script. It made understanding what's going on so much easier. :)

> * I have a main repository which has some submodules defined.
> * One of the submodules is a common submodule which is also included
> in one of the other submodules
> * When running `git fetch --recurse-submodules` I get an error.

I think the presence of common_submodule in the main repo is actually a red herring. if you remove the last two lines of this stanza:

> git setup main_repos
> pushd main_repos
> git submodule add ../common_submodule
> git commit -m 'added submodule to main_repos'
the outcome is the same.
> # This line fails with error code 1 "Could not access submodule
> 'common_submodule'"
> git fetch --recurse-submodules

It looks like "fetch" is smart enough to initialize a submodule when necessary, but not smart enough to do so recursively. If I replace that line with:

  git submodule update --init --recursive
then it works as I'd expect. Likewise, cloning the repository with:
  git clone --recurse-submodules main_repos foo
does what you'd want.

After that, I think "git fetch --recurse-submodules" does what you want, because the submodule repository is already initialized.

I'm not sure to what degree git-fetch intended to support initializing submodules. But it certainly seems like a bug that it handles the top layer but does not recurse (i.e., it should either handle all or none).

Hopefully the commands above at least give you a workaround.
-Peff
Previous: Jesper Rønn-JensenNext: Jesper Rønn-Jensen
Message 2 of 3 in “Error fetching submodule from submodule”
  1. Jesper Rønn-JensenMar 7, 2019
  2. Jeff KingMar 7, 2019
  3. Jesper Rønn-JensenMar 8, 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.