git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* Error fetching submodule from submodule
@ 2019-03-07 11:07 Jesper Rønn-Jensen
  2019-03-07 18:08 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Rønn-Jensen @ 2019-03-07 11:07 UTC (permalink / raw)
  To: git

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).

* 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.

The error is "Could not access submodule 'common_submodule'"

```
$ git --version
git version 2.21.0
```

I created the following script to show (using Git-extras `git create`
to simplify):


```
#!/usr/bin/env bash

if [ "$FORCE" = 'true' ]; then
  rm -rf submodule_experiment
fi

if [ -e submodule_experiment ]; then
  echo FATAL: folder submodule_experiment must not exist. Remove with FORCE=true
  exit 9
fi

mkdir submodule_experiment
pushd submodule_experiment

git setup common_submodule
pushd common_submodule
echo 'common file' > common.txt
git add common.txt
git commit -m 'a file in the common submodule'

popd

git setup other_submodule
pushd other_submodule
git submodule add ../common_submodule
git commit -m 'added submodule to other_submodule'

popd

git setup main_repos
pushd main_repos
git submodule add ../common_submodule
git commit -m 'added submodule to main_repos'

git submodule add ../other_submodule
git commit -m 'added other_submodule to main_repos'


# This line fails with error code 1 "Could not access submodule
'common_submodule'"
git fetch --recurse-submodules

```

Question:
Is this a bug in Git or am I declaring the common submodule in an incorrect way?


-- 

Jesper Rønn-Jensen
Nine A/S
Mobile: +45 2989 1822
Blog http://justaddwater.dk/
jesperrr@gmail.com (Private e-mail and Google Talk IM)

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

* Re: Error fetching submodule from submodule
  2019-03-07 11:07 Error fetching submodule from submodule Jesper Rønn-Jensen
@ 2019-03-07 18:08 ` Jeff King
  2019-03-08  8:50   ` Jesper Rønn-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2019-03-07 18:08 UTC (permalink / raw)
  To: Jesper Rønn-Jensen; +Cc: git

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

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

* Re: Error fetching submodule from submodule
  2019-03-07 18:08 ` Jeff King
@ 2019-03-08  8:50   ` Jesper Rønn-Jensen
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Rønn-Jensen @ 2019-03-08  8:50 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Thanks Jeff

You are completely right! It works as I expect if I remember the extra
parameter `--recursive` when doing `git submodule update --init
--recursive`

Thanks a lot for your feedback! This is really useful! I learned a
useful thing today :)

/Jesper

On Thu, Mar 7, 2019 at 7:08 PM Jeff King <peff@peff.net> wrote:
>
> 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



-- 

Jesper Rønn-Jensen
Nine A/S
Mobile: +45 2989 1822
Blog http://justaddwater.dk/
jesperrr@gmail.com (Private e-mail and Google Talk IM)

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

end of thread, other threads:[~2019-03-08  8:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 11:07 Error fetching submodule from submodule Jesper Rønn-Jensen
2019-03-07 18:08 ` Jeff King
2019-03-08  8:50   ` Jesper Rønn-Jensen

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git