{"thread":{"id":"53018","subject":"git submodule init initialises submodules for which active=false has been defined","startedAt":"2020-03-18T12:50:44Z","lastAt":"2020-10-06T00:25:57Z","messageCount":2,"participants":["Timur Delahaye","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"393393","messageId":"HE1PR04MB2987A255BC327320D1DDFE6692F70@HE1PR04MB2987.eurprd04.prod.outlook.com","threadId":"53018","inReplyTo":null,"subject":"git submodule init initialises submodules for which active=false has been defined","fromName":"Timur Delahaye","fromEmail":"timur.delahaye@corpowerocean.com","sentAt":"2020-03-18T12:50:36Z","receivedAt":"2020-03-18T12:50:44Z","isPatch":false,"sender":{"key":"timur.delahaye@corpowerocean.com","avatar":null},"body":"Hello,\n\nI am trying to prevent\ngit clone --recurse-submodules\nfrom installing some of the submodules of the repo that are not necessary to most users.\n\nHere is what I did:\nIn my main-project\n\ngit submodule add --name one url1\ngit submodule add --name two url2\n\nThen I edited .gitmodules as follows\n\n[submodule \"one\"]\n active = false\n url = url1\n[submodule \"two\"]\n active = true\n url = url2\n\ncommited and pushed.\n\n\nFrom a fresh folder when I run\ngit clone --recurse-submodules main-repo-url\nboth \"one\" and \"two\" get installed\n\nLikewise if I do\ngit clone main-repo-url\ngit submodule init\nboth \"one\" and \"two\" are installed and appear in .git/config as well as .git/modules/\n\nFrom reading https://git-scm.com/docs/gitsubmodules/2.25.0 my understanding was that both procedures should have installed only \"two\" and that I should have needed to do\ngit submodule init one\nin order to force the local installation of the inactive module \"one\".\n\nEither I misunderstood the manual or there is a bug with\ngit submodule init\n\nI am using git version 2.17.1 on Ubuntu 18.04\n\n\nIf this is not a bug but an error on my side, I would really appreciate some explanation about the active=false flag so I can achieve my purpose.\n\nFaithfully yours,\n\n\nTimur\n\n"},{"id":"406981","messageId":"CE0C9CE4-7F18-4151-8F44-3467EF55DFAA@gmail.com","threadId":"53018","inReplyTo":"HE1PR04MB2987A255BC327320D1DDFE6692F70@HE1PR04MB2987.eurprd04.prod.outlook.com","subject":"Re: git submodule init initialises submodules for which active=false has been defined","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-10-06T00:25:49Z","receivedAt":"2020-10-06T00:25:57Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Timur, \n\n> Le 18 mars 2020 à 08:50, Timur Delahaye <timur.delahaye@corpowerocean.com> a écrit :\n> \n> Hello,\n> \n> I am trying to prevent\n> git clone --recurse-submodules\n> from installing some of the submodules of the repo that are not necessary to most users.\n\nOK. \n\n> Here is what I did:\n> In my main-project\n> \n> git submodule add --name one url1\n> git submodule add --name two url2\n> \n> Then I edited .gitmodules as follows\n> \n> [submodule \"one\"]\n> active = false\n> url = url1\n> [submodule \"two\"]\n> active = true\n> url = url2\n\nNote: this could've been done with\n\n    git config -f .gitmodules submodule.one.active false\n    git config -f .gitmodules submodule.two.active true\n\n> commited and pushed.\n> \n> From a fresh folder when I run\n> git clone --recurse-submodules main-repo-url\n> both \"one\" and \"two\" get installed\n\nYes. That's working as it should. If you take a look at the `git clone` documentation [1], \nyou'll see that using '--recurse-submodules' without a pathspec will \nclone and initialize all submodules, and write '.' as the value of 'submodule.active'\n(meaning, all submodules in the superproject are interesting).\n\nIf you do \n\n    git clone --recurse-submodules=two main-repo-url\n\nthen only \"two\" is cloned and initialized, but I think you're looking for something\nmore automatic than that.\n\n> Likewise if I do\n> git clone main-repo-url\n> git submodule init\n> both \"one\" and \"two\" are installed and appear in .git/config as well as .git/modules/\n\nI would say that this is also working as it should. If you read \nthe documentation  for `git submodule init` [2], \nyou'll see that \n\n    \"If no path is specified and submodule.active has been configured,\n     submodules configured to be active will be initialized, \n     otherwise all submodules are initialized.\"\n\nNote: nothing appears in .git/modules after `git submodule init`, \nbut only after `git submodule update`, which is the logical next step\n(or, you could do it in one step with `git submodule update --init)\n\nI after your clone you instead do\n\n   git submodule update --init two\n\nthen you'll get what you want (but again, I think you're looking for an automatic\nway to do it that does not require spelling out \"two\" at or after the 'clone' step.)\nNotice that if after your clone you do\n\n    git config submodule.active two\n    git submodule update --init\n\nThen you get the same result (this is essentially what \n`git clone --recurse-submodules=two ...` does).\n\n> From reading https://git-scm.com/docs/gitsubmodules/2.25.0 my understanding was that both procedures should have installed only \"two\" and that I should have needed to do\n> git submodule init one\n> in order to force the local installation of the inactive module \"one\".\n> \n> Either I misunderstood the manual or there is a bug with\n> git submodule init\n\nI'd be interested to know which section of gitsubmodules(7) made you think that the 'active' \nsetting would work in the way you're describing here, so it could be improved. \n(I have a feeling it's the sentence \"Git only recurses into active submodules\n (see \"ACTIVE SUBMODULES\" section below).\", but maybe there are other places).\n\nNow, let's see if we can actually somehow achieve what you want to do.\nIf you read gitmodules(5) [3], you'll notice that 'submodule.<name>.active' is not\nlisted in the list of settings that can be found in a '.gitmodules' file ! So whatever\nyou were expecting Git to do with these settings is not happening. \nHowever, you'll also notice the setting `submodule.<name>.update`, which \ncan be set to 'none' (see also [4]). And this, I think, is closer to what you want:\n\n       git config -f .gitmodules submodule.one.update none\n \nTry it out! with such a '.gitmodules', then \n\n   git clone --recurse-submodules\n\ngives the following output:\n\n$ git clone super-update/ clone-update --recurse-submodules \nCloning into 'clone-update'...\ndone.\nSubmodule 'one' (/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/one) registered for path 'one'\nSubmodule 'two' (/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/two) registered for path 'two'\nSkipping submodule 'one'\nCloning into '/private/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/clone-update/two'...\ndone.\nSubmodule path 'two': checked out 'd02974612a8f64c1fff7e9de1d90d488606103d2'\n\nand 'one' is neither cloned nor checked out. Similarly you can do\n\n    git clone super-update clone-update\n    cd clone-update\n    git submodule update --init\n\nand the last command outputs:\n\n$ git submodule update --init\nSubmodule 'one' (/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/one) registered for path 'one'\nSubmodule 'two' (/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/two) registered for path 'two'\nSkipping submodule 'one'\nCloning into '/private/var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/submodule-active/clone-update/two'...\ndone.\nSubmodule path 'two': checked out 'd02974612a8f64c1fff7e9de1d90d488606103d2'\n\nand 'one' is neither cloned nor checked out. \n\n> If this is not a bug but an error on my side, I would really appreciate some explanation about the active=false flag so I can achieve my purpose.\n\nI hope the above helps! \nNote that I don't have a lot of experience with the 'submodule.<name>.update=none'\nsetting, (especially how it interacts with `git checkout --recurse-submodules`)\nso I'd be really interested to know if the approach above works for you.\n\n\nCheers,\n\nPhilippe.\n\n[1] https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---recurse-submodulesltpathspecgt\n[2] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-init--ltpathgt82308203\n[3] https://git-scm.com/docs/gitmodules\n[4] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-none"}]}