# Problem with multiples levels of submodules

2 messages from 2024-06-25 to 2024-07-02. Participants: Jeppe Øland.
Thread: https://gitlist.dev/t/61680

## Jeppe Øland, 2024-06-25 22:54

Subject: Problem with multiples levels of submodules
Message-ID: <CA+osTZWaDpH_ZcEhHKrzcaWmHjTAiiWfPmf6C9u3NnzmY0PghQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BosTZWaDpH_ZcEhHKrzcaWmHjTAiiWfPmf6C9u3NnzmY0PghQ%40mail.gmail.com

```
Hi there,

I'm seeing a strange thing with multi-level submodules.
Not sure what's going on, but it feels like a bug.
(I'm doing this on git "2.45.2.windows.1").

For a while, I've been globally setting the recursive and active config options:
    git config --global submodule.recurse true
    git config --global submodule.active .
This has the benefit that I don't need to "git submodule init" new
modules since everything is active.

The weirdness happens when there are submodules within a submodule.

I can reproduce it by just creating 3 git repositories (I have only
tried with GH hosted repos, maybe its different if done locally).
Each repo has a directory within it, and that directory is a submodule
of the next one.
    top -> middle -> bottom

Now, if I don't set the global config above, I can:
    "git clone --recurse-submodules <PATH>" to get everything.
Or:
    "git clone <PATH>", "cd", "git submodule init", "git pull" etc. to
again get everything.

But if I set the global options, I can do:
    "git clone <PATH>" to clone the top level.
    "cd top" to go in there.
    "git pull" to update everything, including submodules.
But while cloning "middle", it gives me an error:
    fatal: not a git repository: ../../.git/modules/middle/modules/bottom

Something is getting confused and thinks there are worktrees involved:
    ".git/modules/middle/config" has "worktree" line in the [core]
section (this appears to be normal).
    ".git/modules/middle/modules/bottom/config" is not a repository,
but just a "[core] worktree" section (definitely not normal).

This all works fine if there is only one level of submodules (top->middle).

Any ideas?

Regards,
-Jeppe

```

## Jeppe Øland, 2024-07-02 00:08

Subject: Re: Problem with multiples levels of submodules
Message-ID: <CA+osTZVMiZDihhiALb7fDO=Q5ntSmUFe6q1YpL=pkzC_tsmoBw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BosTZVMiZDihhiALb7fDO%3DQ5ntSmUFe6q1YpL%3DpkzC_tsmoBw%40mail.gmail.com
In-Reply-To: <CA+osTZWaDpH_ZcEhHKrzcaWmHjTAiiWfPmf6C9u3NnzmY0PghQ@mail.gmail.com>

```
Hi again,

So I made a repro - it even fails locally (you have to explicitly
allow submodules to work with "file" transport).

Try the following:
git config --global protocol.file.allow always

mkdir bottom
cd bottom
git init
echo hello > bottom.txt
git add .
git commit -m Bottom
cd ..

mkdir middle
cd middle
git init
echo hello > middle.txt
git add .
git commit -m Middle
git submodule add ../bottom bottom
git commit -m MiddleSub
cd ..

mkdir top
cd top
git init
echo hello > top.txt
git add .
git commit -m Top
git submodule add ../middle middle
git commit -m TopSub
cd ..

git clone --recurse-submodules top clone_ok

git config --global submodule.recurse true
git config --global submodule.active .

git clone --recurse-submodules top clone_err

Note: If those submodule settings are set initially, then even
creating the top repository fails.

Regards,
-Jeppe

On Tue, Jun 25, 2024 at 3:54 PM Jeppe Øland <joland@gmail.com> wrote:
>
> Hi there,
>
> I'm seeing a strange thing with multi-level submodules.
> Not sure what's going on, but it feels like a bug.
> (I'm doing this on git "2.45.2.windows.1").
>
> For a while, I've been globally setting the recursive and active config options:
>     git config --global submodule.recurse true
>     git config --global submodule.active .
> This has the benefit that I don't need to "git submodule init" new
> modules since everything is active.
>
> The weirdness happens when there are submodules within a submodule.
>
> I can reproduce it by just creating 3 git repositories (I have only
> tried with GH hosted repos, maybe its different if done locally).
> Each repo has a directory within it, and that directory is a submodule
> of the next one.
>     top -> middle -> bottom
>
> Now, if I don't set the global config above, I can:
>     "git clone --recurse-submodules <PATH>" to get everything.
> Or:
>     "git clone <PATH>", "cd", "git submodule init", "git pull" etc. to
> again get everything.
>
> But if I set the global options, I can do:
>     "git clone <PATH>" to clone the top level.
>     "cd top" to go in there.
>     "git pull" to update everything, including submodules.
> But while cloning "middle", it gives me an error:
>     fatal: not a git repository: ../../.git/modules/middle/modules/bottom
>
> Something is getting confused and thinks there are worktrees involved:
>     ".git/modules/middle/config" has "worktree" line in the [core]
> section (this appears to be normal).
>     ".git/modules/middle/modules/bottom/config" is not a repository,
> but just a "[core] worktree" section (definitely not normal).
>
> This all works fine if there is only one level of submodules (top->middle).
>
> Any ideas?
>
> Regards,
> -Jeppe

```
