{"thread":{"id":"59078","subject":"Bug report: checkout --recurse-submodules failing","startedAt":"2023-01-12T12:19:26Z","lastAt":"2023-01-13T14:02:09Z","messageCount":2,"participants":["Carlos Gonzalez","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"470169","messageId":"CWXP265MB3688191D75A56F27A0C4DDB69CFD9@CWXP265MB3688.GBRP265.PROD.OUTLOOK.COM","threadId":"59078","inReplyTo":null,"subject":"Bug report: checkout --recurse-submodules failing","fromName":"Carlos Gonzalez","fromEmail":"carlos.gonzalez@codeplay.com","sentAt":"2023-01-12T12:17:25Z","receivedAt":"2023-01-12T12:19:26Z","isPatch":false,"sender":{"key":"carlos.gonzalez@codeplay.com","avatar":null},"body":"What did you do before the bug happened? \n\nChecking out a custom commit or tag using `--recurse-submodules`, where the specific commit contained a submodule\nnot included in the main branch. The checkout command failed. (Detailed steps below)\n\nWhat did you expect to happen? \n\nThe repository should be checked out to the specified commit and submodules updated, and the one missing in the main \nbranch, cloned.\n\nWhat happened instead? \n\ngit checkout --recurse-submodules submodule\nfatal: not a git repository: ../.git/modules/sycl-blas\nfatal: could not reset submodule index\n\nWhat's different between what you expected and what actually happened?\n\nThis only fails when the repository was cloned with --recursive flag.\n\nAnything else you want to add:\n\nI wrote these simple steps to reproduce:\n\nmkdir repo1 && cd repo1\ngit init\ngit submodule add --name sycl-blas  https://github.com/codeplaysoftware/sycl-blas.git\ngit commit -m \"Adding submodule\"\ngit tag -a submodule -m submodule\ngit submodule deinit sycl-blas\ntruncate -s 0 .gitmodules\nrm -rf sycl-blas/\ngit add .gitmodules\ngit rm sycl-blas\ngit commit -m \"Remove submodule\"\ncd ../\n\n# When repository is cloned without `--recursive`, checkout works\ngit clone repo1 cloned-repo1\ncd cloned-repo1\ngit checkout --recurse-submodules submodule # ok\ncd ../\n# When repository is cloned with `--recursive`, checkout fails\ngit clone --recursive repo1 cloned-repo2\ncd cloned-repo2\ngit checkout --recurse-submodules submodule\nfatal: not a git repository: ../.git/modules/sycl-blas\nfatal: could not reset submodule index\n\n[System Info]\ngit version:\ngit version 2.34.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.14.0-1055-oem #62-Ubuntu SMP Wed Nov 30 04:54:03 UTC 2022 x86_64\ncompiler info: gnuc: 11.2\nlibc info: glibc: 2.35\n$SHELL (typically, interactive shell): <unset>\n\n\n[Enabled Hooks]\n\nBest regards, \nCarlos\n\n\nCarlos Gonzalez Vila\n\nCodeplay Software Ltd\nThis 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\n"},{"id":"470257","messageId":"c587b501-494a-bb9c-4789-dc78f4ad655b@gmail.com","threadId":"59078","inReplyTo":"CWXP265MB3688191D75A56F27A0C4DDB69CFD9@CWXP265MB3688.GBRP265.PROD.OUTLOOK.COM","subject":"Re: Bug report: checkout --recurse-submodules failing","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-01-13T13:58:48Z","receivedAt":"2023-01-13T14:02:09Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Carlos,\n\nLe 2023-01-12 à 07:17, Carlos Gonzalez a écrit :\n> What did you do before the bug happened? \n> \n> Checking out a custom commit or tag using `--recurse-submodules`, where the specific commit contained a submodule\n> not included in the main branch. The checkout command failed. (Detailed steps below)\n> \n> What did you expect to happen? \n> \n> The repository should be checked out to the specified commit and submodules updated, and the one missing in the main \n> branch, cloned.\n\nIt's a reasonable expectation, but the current 'checkout' code does not\nknow how to clone missing submodules.\n\n> \n> What happened instead? \n> \n> git checkout --recurse-submodules submodule\n> fatal: not a git repository: ../.git/modules/sycl-blas\n> fatal: could not reset submodule index\n> \n> What's different between what you expected and what actually happened?\n> \n> This only fails when the repository was cloned with --recursive flag.\n> \n> Anything else you want to add:\n> \n> I wrote these simple steps to reproduce:\n> \n> mkdir repo1 && cd repo1\n> git init\n> git submodule add --name sycl-blas  https://github.com/codeplaysoftware/sycl-blas.git\n> git commit -m \"Adding submodule\"\n> git tag -a submodule -m submodule\n> git submodule deinit sycl-blas\n> truncate -s 0 .gitmodules\n> rm -rf sycl-blas/\n> git add .gitmodules\n> git rm sycl-blas\n> git commit -m \"Remove submodule\"\n> cd ../\n> \n> # When repository is cloned without `--recursive`, checkout works\n> git clone repo1 cloned-repo1\n> cd cloned-repo1\n> git checkout --recurse-submodules submodule # ok\n> cd ../\n> # When repository is cloned with `--recursive`, checkout fails\n> git clone --recursive repo1 cloned-repo2\n> cd cloned-repo2\n> git checkout --recurse-submodules submodule\n> fatal: not a git repository: ../.git/modules/sycl-blas\n> fatal: could not reset submodule index\n\nThanks for a complete reproducer. This has been reported before,\nsee the threads linked at [1].\n\nI was working on that issue last month, so that at least the checkout fails\nin a clean way, but have not gone back to it yet.\n\nIn the meantime, as you've discovered, a workaround is to clone without\n'--recurse-submodules', then manually run 'git submodule update --init --recursive'\nafter switching branches.\n\nCheers,\n\nPhilippe.\n\n[1] https://github.com/gitgitgadget/git/issues/752\n"}]}