{"thread":{"id":"56238","subject":"[BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly","startedAt":"2021-08-08T22:21:43Z","lastAt":"2021-08-08T22:21:43Z","messageCount":1,"participants":["Alexey Izbyshev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"432278","messageId":"85faefc0b1e23ee942b11087089ccc4f@ispras.ru","threadId":"56238","inReplyTo":null,"subject":"[BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly","fromName":"Alexey Izbyshev","fromEmail":"izbyshev@ispras.ru","sentAt":"2021-08-08T22:21:38Z","receivedAt":"2021-08-08T22:21:43Z","isPatch":false,"sender":{"key":"izbyshev@ispras.ru","avatar":null},"body":"Hi,\n\nOn a fresh clone of a repo with submodules, running `git checkout \n--recurse-submodules` after `git submodule init` but without `git \nsubmodule update` fails (as expected), but leaves the working tree in a \nbad state:\n\ngit init repo\ngit -C repo commit --allow-empty -m \"initial\"\ngit -C repo submodule add \"$PWD\"/repo\ngit -C repo commit -m \"add sm\"\ngit clone repo repo-clone\ngit -C repo-clone submodule init repo\ngit -C repo-clone checkout --recurse-submodules repo\nfatal: not a git repository: ../.git/modules/repo\nfatal: could not reset submodule index\n\n(Tested on git 2.17.1 and v2.33.0-rc1)\n\n`git checkout` creates a gitlink in the submodule directory even though \nits target is not a valid git dir (it contains only `config`). In the \nresulting state, many git commands (like `status` and even `submodule \ndeinit`) fail, so while trying to checkout a submodule before `submodule \nupdate` isn't supposed to work, I think it still shouldn't leave the \nrepo in such a state.\n\nIt seems that related issues have already been reported, though those \nthat I've found[1,2,3] describe more complex scenarios, while mine is \nvery basic.\n\nHope it helps,\nAlexey\n\n[1] \nhttps://public-inbox.org/git/20200501005432.h62dnpkx7feb7rto@glandium.org/\n[2] \nhttps://public-inbox.org/git/dab7128d-5ea7-5d7c-1ae1-1d71be316326@gmail.com/\n[3] \nhttps://public-inbox.org/git/CABVQXt5E-R22G62W-tQieA7XiZKZiOA8Hp2xewYhwwOS8wFh0Q@mail.gmail.com/\n\n"}]}