{"thread":{"id":"48712","subject":"RE: fatal: could not reset submodule index","startedAt":"2018-06-14T18:19:35Z","lastAt":"2018-06-18T13:57:28Z","messageCount":3,"participants":["Antoine W. Campagna","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"350180","messageId":"DB6PR0101MB2344D682511891E4E9528598D97D0@DB6PR0101MB2344.eurprd01.prod.exchangelabs.com","threadId":"48712","inReplyTo":null,"subject":"RE: fatal: could not reset submodule index","fromName":"Antoine W. Campagna","fromEmail":"awe@frontmatec.com","sentAt":"2018-06-14T18:19:27Z","receivedAt":"2018-06-14T18:19:35Z","isPatch":false,"sender":{"key":"awe@frontmatec.com","avatar":"https://gravatar.com/avatar/7c7bfeb735f281887abfd8ab6177d7b747ec5aad84d2fa003f82a6a81e38be81?d=mp&s=160"},"body":"On Wed, Jun 13, 2018 at 18:19, Antoine W. Campagna wrote:\n> Here is the full reproduction instructions:\n\nNewlines got mangled, making my message hard to read. Sorry.\n\nHere is the corrected reproduction instructions:\n\n# Create a repository\nmkdir main\ncd main\ngit init\ntouch main.txt\ngit add main.txt\ngit commit -a -m \"Initial commit\"\ncd ..\n\n# Create a second repository\nmkdir sub\ncd sub\ngit init\ntouch sub.txt\ngit add sub.txt\ngit commit -a -m \"Initial commit of repo sub\"\ncd ..\n\n# Add the second repository as submodule, on a separate branch\ncd main\ngit branch with-submodule\ngit checkout with-submodule\ngit submodule add ../sub sub\ngit commit -a -m \"Add submodule\"\n\n# Set main repo back to master branch (without the submodule)\ngit checkout master\ncd ..\n\n# Make a clone and checkout the branch\ngit clone main clone1\ncd clone1\ngit checkout with-submodule\n# Submodule is not automatically updated (sub folder is empty)\ngit submodule update --init --recursive\n# Now the submodule content is there\n# But I want to automatically update submodules when checking out a branch\ncd ..\n\n# Trying again, adding --recursive during clone\ngit clone --recursive main clone2\ncd clone2\ngit checkout with-submodule\n# Submodule is still not automatically updated (sub folder is empty)\ngit submodule update --init --recursive\ncd ..\n\n# Trying again, adding --recurse-submodules during checkout\ngit clone --recursive main clone3\ncd clone3\ngit checkout --recurse-submodules with-submodule\n# Fails with these error messages :\n#\tfatal: not a git repository: ../.git/modules/sub\n#\tfatal: could not reset submodule index\n# It seems like Git tries to update the submodule but without having initialized the submodule cd ..\n\n# Trying again with submodule.recurse\ngit config --global submodule.recurse true\ngit clone main clone4 cd clone4\ngit checkout with-submodule\n# Submodule is still not automatically updated (sub folder is empty)\n# It seems like submodule.recurse does not affect git clone\n\n# Trying again with both submodule.recurse and --recursive\ngit config --global submodule.recurse true\ngit clone --recursive main clone5 cd clone5\ngit checkout with-submodule\n# Fails with these error messages :\n#\tfatal: not a git repository: ../.git/modules/sub\n#\tfatal: could not reset submodule index\n# Same issue as with \"git checkout --recurse-submodules\"\n\n"},{"id":"350294","messageId":"CAGZ79kYUyzJK7a+=bQMxi=YJ5LgkS_2eJA1dB325U71ks1jjGg@mail.gmail.com","threadId":"48712","inReplyTo":"DB6PR0101MB2344D682511891E4E9528598D97D0@DB6PR0101MB2344.eurprd01.prod.exchangelabs.com","subject":"Re: fatal: could not reset submodule index","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-06-15T19:47:13Z","receivedAt":"2018-06-15T19:47:28Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"> # Trying again with submodule.recurse\n> git config --global submodule.recurse true\n> git clone main clone4 cd clone4\n> git checkout with-submodule\n> # Submodule is still not automatically updated (sub folder is empty)\n> # It seems like submodule.recurse does not affect git clone\n\nThat is true; submodule.recurse is not affecting git clone.\nThis was a design decision once it was introduced, as the git clone\nmight be too large. Maybe we need to revisit that decision and\njust clone the submodules if submodule.recurse is set.\n\nThe problem that this bug report highlights, is the following:\nEach branch has its own .gitmodules file and they can be\nall different, however at clone time we only clone submodules\nfrom the currently active branch.\n\nSo you could get your test case to pass with\n    git clone --branch with-submodule main clone5\n"},{"id":"350382","messageId":"DB6PR0101MB23445AE7C96E5108B544D015D9710@DB6PR0101MB2344.eurprd01.prod.exchangelabs.com","threadId":"48712","inReplyTo":"CAGZ79kYUyzJK7a+=bQMxi=YJ5LgkS_2eJA1dB325U71ks1jjGg@mail.gmail.com","subject":"RE: fatal: could not reset submodule index","fromName":"Antoine W. Campagna","fromEmail":"awe@frontmatec.com","sentAt":"2018-06-18T13:57:22Z","receivedAt":"2018-06-18T13:57:28Z","isPatch":false,"sender":{"key":"awe@frontmatec.com","avatar":"https://gravatar.com/avatar/7c7bfeb735f281887abfd8ab6177d7b747ec5aad84d2fa003f82a6a81e38be81?d=mp&s=160"},"body":"> That is true; submodule.recurse is not affecting git clone.\n> This was a design decision once it was introduced, as the git clone might be too large. Maybe we need to revisit that decision and just clone the submodules if submodule.recurse is set.\n>\n> The problem that this bug report highlights, is the following:\n> Each branch has its own .gitmodules file and they can be all different, however at clone time we only clone submodules from the currently active branch.\n>\n> So you could get your test case to pass with\n>     git clone --branch with-submodule main clone5\n> \n\nThank you for your input Stefan.\n\nBut here is our situation : \n7 different projects in separate repositories\nBig parts of the code is similar between the projects\nWe want to extract these similar portions in separate repositories and add them as submodules (maybe about 10 of them).\nWe would do this progressively, adding one submodule at a time.\nWe need to support older versions so we have to keep branches that will not have submodules.\nSince we need to checkout these branches regularly, we would want to have submodule.recurse enabled.\nWith this setup, every time a submodule is added in one of the projects, each developer would get the \"fatal: could not reset submodule index\" error and would be unable to checkout master branch.\n\n"}]}