{"thread":{"id":"50680","subject":"Error fetching submodule from submodule","startedAt":"2019-03-07T11:07:34Z","lastAt":"2019-03-08T08:50:29Z","messageCount":3,"participants":["Jesper Rønn-Jensen","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"370897","messageId":"CAL-rKu6AcyHdrCsVikwQxTgKHgtV86+BeHOv_sTSu-jvwME75Q@mail.gmail.com","threadId":"50680","inReplyTo":null,"subject":"Error fetching submodule from submodule","fromName":"Jesper Rønn-Jensen","fromEmail":"jesperrr@gmail.com","sentAt":"2019-03-07T11:07:21Z","receivedAt":"2019-03-07T11:07:34Z","isPatch":false,"sender":{"key":"jesperrr@gmail.com","avatar":null},"body":"Hi I think I may have found an error in the way git handles a\nsubmodule's submodule. Read further for the example (extracted from a\nreal project).\n\n* I have a main repository which has some submodules defined.\n* One of the submodules is a common submodule which is also included\nin one of the other submodules\n* When running `git fetch --recurse-submodules` I get an error.\n\nThe error is \"Could not access submodule 'common_submodule'\"\n\n```\n$ git --version\ngit version 2.21.0\n```\n\nI created the following script to show (using Git-extras `git create`\nto simplify):\n\n\n```\n#!/usr/bin/env bash\n\nif [ \"$FORCE\" = 'true' ]; then\n  rm -rf submodule_experiment\nfi\n\nif [ -e submodule_experiment ]; then\n  echo FATAL: folder submodule_experiment must not exist. Remove with FORCE=true\n  exit 9\nfi\n\nmkdir submodule_experiment\npushd submodule_experiment\n\ngit setup common_submodule\npushd common_submodule\necho 'common file' > common.txt\ngit add common.txt\ngit commit -m 'a file in the common submodule'\n\npopd\n\ngit setup other_submodule\npushd other_submodule\ngit submodule add ../common_submodule\ngit commit -m 'added submodule to other_submodule'\n\npopd\n\ngit setup main_repos\npushd main_repos\ngit submodule add ../common_submodule\ngit commit -m 'added submodule to main_repos'\n\ngit submodule add ../other_submodule\ngit commit -m 'added other_submodule to main_repos'\n\n\n# This line fails with error code 1 \"Could not access submodule\n'common_submodule'\"\ngit fetch --recurse-submodules\n\n```\n\nQuestion:\nIs this a bug in Git or am I declaring the common submodule in an incorrect way?\n\n\n-- \n\nJesper Rønn-Jensen\nNine A/S\nMobile: +45 2989 1822\nBlog http://justaddwater.dk/\njesperrr@gmail.com (Private e-mail and Google Talk IM)\n"},{"id":"370918","messageId":"20190307180831.GA21404@sigill.intra.peff.net","threadId":"50680","inReplyTo":"CAL-rKu6AcyHdrCsVikwQxTgKHgtV86+BeHOv_sTSu-jvwME75Q@mail.gmail.com","subject":"Re: Error fetching submodule from submodule","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-03-07T18:08:31Z","receivedAt":"2019-03-07T18:08:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 07, 2019 at 12:07:21PM +0100, Jesper Rønn-Jensen wrote:\n\n> Hi I think I may have found an error in the way git handles a\n> submodule's submodule. Read further for the example (extracted from a\n> real project).\n\nFirst off, thank you for the example script. It made understanding\nwhat's going on so much easier. :)\n\n> * I have a main repository which has some submodules defined.\n> * One of the submodules is a common submodule which is also included\n> in one of the other submodules\n> * When running `git fetch --recurse-submodules` I get an error.\n\nI think the presence of common_submodule in the main repo is actually a\nred herring. if you remove the last two lines of this stanza:\n\n> git setup main_repos\n> pushd main_repos\n> git submodule add ../common_submodule\n> git commit -m 'added submodule to main_repos'\n\nthe outcome is the same.\n\n> # This line fails with error code 1 \"Could not access submodule\n> 'common_submodule'\"\n> git fetch --recurse-submodules\n\nIt looks like \"fetch\" is smart enough to initialize a submodule when\nnecessary, but not smart enough to do so recursively. If I replace that\nline with:\n\n  git submodule update --init --recursive\n\nthen it works as I'd expect. Likewise, cloning the repository with:\n\n  git clone --recurse-submodules main_repos foo\n\ndoes what you'd want.\n\nAfter that, I think \"git fetch --recurse-submodules\" does what you want,\nbecause the submodule repository is already initialized.\n\nI'm not sure to what degree git-fetch intended to support initializing\nsubmodules. But it certainly seems like a bug that it handles the top\nlayer but does not recurse (i.e., it should either handle all or none).\n\nHopefully the commands above at least give you a workaround.\n\n-Peff\n"},{"id":"370943","messageId":"CAL-rKu6knyzyVE7VuTRZEKoS9MOU8ip+Nm+HH7dJAOffb46q2w@mail.gmail.com","threadId":"50680","inReplyTo":"20190307180831.GA21404@sigill.intra.peff.net","subject":"Re: Error fetching submodule from submodule","fromName":"Jesper Rønn-Jensen","fromEmail":"jesperrr@gmail.com","sentAt":"2019-03-08T08:50:15Z","receivedAt":"2019-03-08T08:50:29Z","isPatch":false,"sender":{"key":"jesperrr@gmail.com","avatar":null},"body":"Thanks Jeff\n\nYou are completely right! It works as I expect if I remember the extra\nparameter `--recursive` when doing `git submodule update --init\n--recursive`\n\nThanks a lot for your feedback! This is really useful! I learned a\nuseful thing today :)\n\n/Jesper\n\nOn Thu, Mar 7, 2019 at 7:08 PM Jeff King <peff@peff.net> wrote:\n>\n> On Thu, Mar 07, 2019 at 12:07:21PM +0100, Jesper Rønn-Jensen wrote:\n>\n> > Hi I think I may have found an error in the way git handles a\n> > submodule's submodule. Read further for the example (extracted from a\n> > real project).\n>\n> First off, thank you for the example script. It made understanding\n> what's going on so much easier. :)\n>\n> > * I have a main repository which has some submodules defined.\n> > * One of the submodules is a common submodule which is also included\n> > in one of the other submodules\n> > * When running `git fetch --recurse-submodules` I get an error.\n>\n> I think the presence of common_submodule in the main repo is actually a\n> red herring. if you remove the last two lines of this stanza:\n>\n> > git setup main_repos\n> > pushd main_repos\n> > git submodule add ../common_submodule\n> > git commit -m 'added submodule to main_repos'\n>\n> the outcome is the same.\n>\n> > # This line fails with error code 1 \"Could not access submodule\n> > 'common_submodule'\"\n> > git fetch --recurse-submodules\n>\n> It looks like \"fetch\" is smart enough to initialize a submodule when\n> necessary, but not smart enough to do so recursively. If I replace that\n> line with:\n>\n>   git submodule update --init --recursive\n>\n> then it works as I'd expect. Likewise, cloning the repository with:\n>\n>   git clone --recurse-submodules main_repos foo\n>\n> does what you'd want.\n>\n> After that, I think \"git fetch --recurse-submodules\" does what you want,\n> because the submodule repository is already initialized.\n>\n> I'm not sure to what degree git-fetch intended to support initializing\n> submodules. But it certainly seems like a bug that it handles the top\n> layer but does not recurse (i.e., it should either handle all or none).\n>\n> Hopefully the commands above at least give you a workaround.\n>\n> -Peff\n\n\n\n-- \n\nJesper Rønn-Jensen\nNine A/S\nMobile: +45 2989 1822\nBlog http://justaddwater.dk/\njesperrr@gmail.com (Private e-mail and Google Talk IM)\n"}]}