threads / bug / 59078

Bug report: checkout --recurse-submodules failing

Subject: Bug report: checkout --recurse-submodules failing

## tl;dr

2 messages between Jan 12, 2023 and Jan 13, 2023.

replies: 1people: 2as markdown or json

Carlos Gonzalez· Jan 12, 2023, 12:17 UTC · lore
What did you do before the bug happened? 

Checking out a custom commit or tag using `--recurse-submodules`, where the specific commit contained a submodule not included in the main branch. The checkout command failed. (Detailed steps below)

What did you expect to happen? 

The repository should be checked out to the specified commit and submodules updated, and the one missing in the main branch, cloned.

What happened instead? 

git checkout --recurse-submodules submodule fatal: not a git repository: ../.git/modules/sycl-blas fatal: could not reset submodule index

What's different between what you expected and what actually happened?
This only fails when the repository was cloned with --recursive flag.
Anything else you want to add:
I wrote these simple steps to reproduce:

mkdir repo1 && cd repo1 git init git submodule add --name sycl-blas https://github.com/codeplaysoftware/sycl-blas.git git commit -m "Adding submodule" git tag -a submodule -m submodule git submodule deinit sycl-blas truncate -s 0 .gitmodules rm -rf sycl-blas/ git add .gitmodules git rm sycl-blas git commit -m "Remove submodule" cd ../

# When repository is cloned without `--recursive`, checkout works git clone repo1 cloned-repo1 cd cloned-repo1 git checkout --recurse-submodules submodule # ok cd ../ # When repository is cloned with `--recursive`, checkout fails git clone --recursive repo1 cloned-repo2 cd cloned-repo2 git checkout --recurse-submodules submodule fatal: not a git repository: ../.git/modules/sycl-blas fatal: could not reset submodule index

[System Info] git version: git version 2.34.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.14.0-1055-oem #62-Ubuntu SMP Wed Nov 30 04:54:03 UTC 2022 x86_64 compiler info: gnuc: 11.2 libc info: glibc: 2.35 $SHELL (typically, interactive shell): <unset>

[Enabled Hooks]

Best regards, Carlos

Carlos Gonzalez Vila

Codeplay Software Ltd This message is private and confidential. If you have received this message in error, please notify us and remove it from your system. Company registered in England and Wales, number: 04567874. Registered office: 2 New Bailey, 6 Stanley Street, Salford, Greater Manchester, United Kingdom, M3 5GS

Philippe Blain· Jan 13, 2023, 13:58 UTC · re: Carlos Gonzalez · lore

Re: Bug report: checkout --recurse-submodules failing

Hi Carlos,
Le 2023-01-12 à 07:17, Carlos Gonzalez a écrit :
Show 9 quoted lines
> What did you do before the bug happened? 
> 
> Checking out a custom commit or tag using `--recurse-submodules`, where the specific commit contained a submodule
> not included in the main branch. The checkout command failed. (Detailed steps below)
> 
> What did you expect to happen? 
> 
> The repository should be checked out to the specified commit and submodules updated, and the one missing in the main 
> branch, cloned.

It's a reasonable expectation, but the current 'checkout' code does not know how to clone missing submodules.

Show 39 quoted lines
> 
> What happened instead? 
> 
> git checkout --recurse-submodules submodule
> fatal: not a git repository: ../.git/modules/sycl-blas
> fatal: could not reset submodule index
> 
> What's different between what you expected and what actually happened?
> 
> This only fails when the repository was cloned with --recursive flag.
> 
> Anything else you want to add:
> 
> I wrote these simple steps to reproduce:
> 
> mkdir repo1 && cd repo1
> git init
> git submodule add --name sycl-blas  https://github.com/codeplaysoftware/sycl-blas.git
> git commit -m "Adding submodule"
> git tag -a submodule -m submodule
> git submodule deinit sycl-blas
> truncate -s 0 .gitmodules
> rm -rf sycl-blas/
> git add .gitmodules
> git rm sycl-blas
> git commit -m "Remove submodule"
> cd ../
> 
> # When repository is cloned without `--recursive`, checkout works
> git clone repo1 cloned-repo1
> cd cloned-repo1
> git checkout --recurse-submodules submodule # ok
> cd ../
> # When repository is cloned with `--recursive`, checkout fails
> git clone --recursive repo1 cloned-repo2
> cd cloned-repo2
> git checkout --recurse-submodules submodule
> fatal: not a git repository: ../.git/modules/sycl-blas
> fatal: could not reset submodule index

Thanks for a complete reproducer. This has been reported before, see the threads linked at [1].

I was working on that issue last month, so that at least the checkout fails in a clean way, but have not gone back to it yet.

In the meantime, as you've discovered, a workaround is to clone without '--recurse-submodules', then manually run 'git submodule update --init --recursive' after switching branches.

Cheers,
Philippe.
[1] https://github.com/gitgitgadget/git/issues/752

← back to recent threads