{"thread":{"id":"47903","subject":"Issue in switching branches with different submodules","startedAt":"2018-02-22T12:10:18Z","lastAt":"2018-02-24T00:36:13Z","messageCount":2,"participants":["christian.zitzmann@continental-corporation.com","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"339921","messageId":"OF65A78D43.F69630E3-ONC125823B.0057EE88-C125823C.0042D7B0@continental-corporation.com","threadId":"47903","inReplyTo":null,"subject":"Issue in switching branches with different submodules","fromName":"","fromEmail":"christian.zitzmann@continental-corporation.com","sentAt":"2018-02-22T12:10:05Z","receivedAt":"2018-02-22T12:10:18Z","isPatch":false,"sender":{"key":"christian.zitzmann@continental-corporation.com","avatar":null},"body":"Hello,\nI've found an issue in git when working with submodules.\nMy Project is set up using hundreds of components by submodules (and \nnested submodules), that are independent created in central development \ngroups.\nNow it occurs that the structure of the submodules is changed over time.\n\nE.g.\nProject1(OldBranch)\n  - ComponentX/SubComp1 -> ssh://Server/ComponentX/SubComp1\n  - ComponentX/SubComp2 -> ssh://Server/ComponentX/SubComp2\n  - ComponentX/SubComp2 -> ssh://Server/ComponentX/SubComp2\n\nProject1(Masster)\n  - ComponentX-> ssh://Server/ComponentX\n\nThere is both a repository for the old subcomponents, and for the new \nComponent on the server.\n\nWhen trying to switch between the branches all git commands are failing.\nIt seems like most git commands are not creating the SubComponent \nsubmodules because the .git file from the Component is not deleted\n\nA 'git submodule sync' fails with:\nfatal: Not a git repository: \nD:/Project1/ComponentX/../.git/modules/ComponentX\n\nLooking into the folders I see:\nD:/Project1/.git/modules/ComponentX/SubComp1\nD:/Project1/.git/modules/ComponentX/SubComp2\nD:/Project1/.git/modules/ComponentX/SubComp3\nD:/Project1/ComponentX/.git (file)\n\nA 'git submodule update --init also fails with this folders\nNeither a forced checkout or a hard reset is working.\n\nSimilar errors can occur when switching between branches with a different \nnumber of components used as submodules vs. project specific content.\nAs a result it happens that people are working with an incosistend state \nof the working directory.\n\nMy expectation would be that, when switching between branches/commits with \na git checkout --recurse-submodules the branche including all submodules \nis checked out fully to exactly the state of the desired branch/commit\nI.e the following usecases are an issue\n- Deleted submodule\n- Added submodule as replacement of local directory\n- Changed remote location of submodule (One component is available from \ndifferent providers having individual repositories)\n- Restructured Component (see example)\n\nSimilar issues are existing when creating the new structure to commit it, \nbut here the error is more obvious and people are manually deleting as \nmuch as required to get the new submodules correctly in.\n\nBest regards\n\nChristian Zitzmann\n\n\nP HEV E SW SF PMT\n\nContinental Automotive GmbH\nSiemensstrasse 12, 93055 Regensburg, Germany\n\nTelefon/Phone: +49 941 790-7265\nE-Mail: Christian.Zitzmann@continental-corporation.com\n"},{"id":"340113","messageId":"CAGZ79kZPFF-htksHsnRSDpScWoCLap5Az+s=09htx_0Tz2_u8A@mail.gmail.com","threadId":"47903","inReplyTo":"OF65A78D43.F69630E3-ONC125823B.0057EE88-C125823C.0042D7B0@continental-corporation.com","subject":"Re: Issue in switching branches with different submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-24T00:36:07Z","receivedAt":"2018-02-24T00:36:13Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Feb 22, 2018 at 4:10 AM,\n<Christian.Zitzmann@continental-corporation.com> wrote:\n> Hello,\n> I've found an issue in git when working with submodules.\n> My Project is set up using hundreds of components by submodules (and\n> nested submodules), that are independent created in central development\n> groups.\n> Now it occurs that the structure of the submodules is changed over time.\n>\n> E.g.\n> Project1(OldBranch)\n>   - ComponentX/SubComp1 -> ssh://Server/ComponentX/SubComp1\n>   - ComponentX/SubComp2 -> ssh://Server/ComponentX/SubComp2\n>   - ComponentX/SubComp2 -> ssh://Server/ComponentX/SubComp2\n>\n> Project1(Masster)\n>   - ComponentX-> ssh://Server/ComponentX\n>\n> There is both a repository for the old subcomponents, and for the new\n> Component on the server.\n\nok, so you're saying this is all a client side problem?\n\n> When trying to switch between the branches all git commands are failing.\n> It seems like most git commands are not creating the SubComponent\n> submodules because the .git file from the Component is not deleted\n>\n> A 'git submodule sync' fails with:\n> fatal: Not a git repository:\n> D:/Project1/ComponentX/../.git/modules/ComponentX\n>\n> Looking into the folders I see:\n> D:/Project1/.git/modules/ComponentX/SubComp1\n> D:/Project1/.git/modules/ComponentX/SubComp2\n> D:/Project1/.git/modules/ComponentX/SubComp3\n> D:/Project1/ComponentX/.git (file)\n\nAs a quick workaround to repair your current corrupted repo,\nyou can just delete the .git file, which presumably contains\n\n  gitdir: ../.git/modules/ComponentX\n\nI think this reveals (yet another) problem that we have with\nwith submodule names. Submodules used to have its git directory\ninside its own working tree, but now they are encouraged to have\nit in the superproject in .git/modules/<name>.\n\nConsidering your submodules\n    \"ComponentX/...\"\n    \"ComponentX\"\nyou may have a directory conflict, because there is already a\ndirectory named \"ComponentX\" so we cannot store the later\nsubmodules git directory.\n\n> A 'git submodule update --init also fails with this folders\n> Neither a forced checkout or a hard reset is working.\n\nFor this problem you could manually repair the superproject by\ngiving better names to submodules, such that you have unique\nnames, such that one is not the prefix directory of another.\n\n> Similar errors can occur when switching between branches with a different\n> number of components used as submodules vs. project specific content.\n> As a result it happens that people are working with an incosistend state\n> of the working directory.\n>\n> My expectation would be that, when switching between branches/commits with\n> a git checkout --recurse-submodules the branche including all submodules\n> is checked out fully to exactly the state of the desired branch/commit\n> I.e the following usecases are an issue\n> - Deleted submodule\n> - Added submodule as replacement of local directory\n> - Changed remote location of submodule (One component is available from\n> different providers having individual repositories)\n> - Restructured Component (see example)\n\nI agree with this expectation and we'd need to discuss how to make this happen\nas the submodule naming scheme doesn't allow for this to work flawlessly.\n\n> Similar issues are existing when creating the new structure to commit it,\n> but here the error is more obvious and people are manually deleting as\n> much as required to get the new submodules correctly in.\n>\n> Best regards\n\nThanks for this bug report; I needed some time to ingest it and come up\nwith speculation on what might be the cause. (Not sure if it is the correct\nroot cause though)\n\nThanks,\nStefan\n"}]}