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

[BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly

From
AIAlexey Izbyshev <izbyshev@ispras.ru>
Date
Aug 8, 2021, 22:21 UTC
Message-ID
<85faefc0b1e23ee942b11087089ccc4f@ispras.ru>
Hi,

On a fresh clone of a repo with submodules, running `git checkout --recurse-submodules` after `git submodule init` but without `git submodule update` fails (as expected), but leaves the working tree in a bad state:

git init repo git -C repo commit --allow-empty -m "initial" git -C repo submodule add "$PWD"/repo git -C repo commit -m "add sm" git clone repo repo-clone git -C repo-clone submodule init repo git -C repo-clone checkout --recurse-submodules repo fatal: not a git repository: ../.git/modules/repo fatal: could not reset submodule index

(Tested on git 2.17.1 and v2.33.0-rc1)

`git checkout` creates a gitlink in the submodule directory even though its target is not a valid git dir (it contains only `config`). In the resulting state, many git commands (like `status` and even `submodule deinit`) fail, so while trying to checkout a submodule before `submodule update` isn't supposed to work, I think it still shouldn't leave the repo in such a state.

It seems that related issues have already been reported, though those that I've found[1,2,3] describe more complex scenarios, while mine is very basic.

Hope it helps, Alexey

[1] https://public-inbox.org/git/20200501005432.h62dnpkx7feb7rto@glandium.org/ [2] https://public-inbox.org/git/dab7128d-5ea7-5d7c-1ae1-1d71be316326@gmail.com/ [3] https://public-inbox.org/git/CABVQXt5E-R22G62W-tQieA7XiZKZiOA8Hp2xewYhwwOS8wFh0Q@mail.gmail.com/

Message 1 of 1 in “[BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly”
  1. Alexey IzbyshevAug 8, 2021

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.