{"thread":{"id":"55126","subject":"The argument \"--recurse-submodules=no\" when doing \"fetch --all\" is not passed to the following commands which can ends up fetching submodules","startedAt":"2021-02-09T16:37:27Z","lastAt":"2021-02-09T17:02:01Z","messageCount":2,"participants":["Dominick Latreille","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"416515","messageId":"DM5PR1701MB1724CCBB1AC5CF342BA9ADD5898E9@DM5PR1701MB1724.namprd17.prod.outlook.com","threadId":"55126","inReplyTo":null,"subject":"The argument \"--recurse-submodules=no\" when doing \"fetch --all\" is not passed to the following commands which can ends up fetching submodules","fromName":"Dominick Latreille","fromEmail":"dominick.latreille@ubisoft.com","sentAt":"2021-02-09T16:35:58Z","receivedAt":"2021-02-09T16:37:27Z","isPatch":false,"sender":{"key":"dominick.latreille@ubisoft.com","avatar":null},"body":"Hi! \n\nI opened the following issue https://github.com/git-for-windows/git/issues/3027  , but it also happen when using git on Linux. I have been told to send an email here for the issue.\n\nThe git version I am using is the following:\n```\ngit version 2.25.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\n```\nTerminal used : Bash\n\nHere is the command I ran to trigger this issue\n```\nGIT_TRACE2=1 git fetch --all --recurse-submodules=no\n```\n\nI expected the submodules to not be fetched and to see this command with traces activated\n```\ngit fetch --append --no-auto-gc --recurse-submodules=no --no-write-commit-graph origin\n```\n\nBut, here is the command line I got with traces activated and the submodules were fetched later on.\n```\ngit fetch --append --no-auto-gc --no-write-commit-graph origin\n```\n\nHere are some repro steps with a repository on GitHub.\n\n1. Clone with git bash https://github.com/DomLatr/RepoWithSubmodule\n2.  In the repo, run the following command : \"git submodule update --init\"\n3. In the file .git\\packed-refs, remove the line \"f5165dbd5441d97e7fba6b55917a4c7865e5d7ee refs/remotes/origin/change-submodule\" to simulate that the repository does not have the branch.\n3a. If the line is not present in \"packed-refs\" or is straight up absent, you can remove the file \".git\\refs\\remotes\\origin\\change-submodule\", that will have the same result.\n4. Run the command : \"GIT_TRACE2=1 git fetch --all --recurse-submodules=no\"\n5. Notice that the submodules **are** fetched since it uses the default value \"--recurse-submodules=on-demand\" instead of the value passed in the CLI\n\nIt happens in a repository with submodules that needs would need to be fetched. The value of \"fetch.recurseSubmodules\" by default is \"on-demand\", which translate to \"yes\" when you need to fetch a new SHA that you don't have locally. I tried the 3 command line possibilities with --recurse-submodules and GIT_TRACE2=1. Here is the following results:\n\nGIT_TRACE2=1 git fetch --all --recurse-submodules=no\n=> git fetch --append --no-auto-gc --no-write-commit-graph origin\n\nGIT_TRACE2=1 git fetch --all --recurse-submodules=on-demand   \n=> git fetch --append --no-auto-gc --no-write-commit-graph --recurse-submodules=on-demand origin\n\nGIT_TRACE2=1 git fetch --all --recurse-submodules=yes\n=> git fetch --append --no-auto-gc --no-write-commit-graph --recurse-submodules origin\n\nSince the  \"--recurse-submodules=no\" is not passed to the following commands that are ran automatically, I can see that it is using the default value of \"--recuse-submodules=on-demand\", which will end up fetching the submodules in this case.\n\nThanks!\n\nDominick\n"},{"id":"416521","messageId":"YCK/yfrDQ3LXP3ec@coredump.intra.peff.net","threadId":"55126","inReplyTo":"DM5PR1701MB1724CCBB1AC5CF342BA9ADD5898E9@DM5PR1701MB1724.namprd17.prod.outlook.com","subject":"Re: The argument \"--recurse-submodules=no\" when doing \"fetch --all\" is not passed to the following commands which can ends up fetching submodules","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-02-09T17:00:57Z","receivedAt":"2021-02-09T17:02:01Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 09, 2021 at 04:35:58PM +0000, Dominick Latreille wrote:\n\n> Here is the command I ran to trigger this issue\n> ```\n> GIT_TRACE2=1 git fetch --all --recurse-submodules=no\n> ```\n> \n> I expected the submodules to not be fetched and to see this command with traces activated\n> ```\n> git fetch --append --no-auto-gc --recurse-submodules=no --no-write-commit-graph origin\n> ```\n> \n> But, here is the command line I got with traces activated and the submodules were fetched later on.\n> ```\n> git fetch --append --no-auto-gc --no-write-commit-graph origin\n> ```\n\nThe issue is that \"fetch --all\" runs fetch sub-processes (one for each\nremote), and tries to copy its arguments to them. But it does so by\nlooking at what it parsed and trying to recreate the relevant set of\noriginal arguments.\n\nAnd it looks like when this was added way back in 7dce19d374\n(fetch/pull: Add the --recurse-submodules option, 2010-11-12), it was\nnot anticipated that somebody would need to turn recursion _off_. :) Of\ncourse it makes perfect sense if somebody later switches the default to\non-demand. :)\n\nSo the solution is probably:\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 91f3d20696..cb59f79157 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1660,6 +1660,8 @@ static void add_options_to_argv(struct strvec *argv)\n \t\tstrvec_push(argv, \"--recurse-submodules\");\n \telse if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)\n \t\tstrvec_push(argv, \"--recurse-submodules=on-demand\");\n+\telse if (recurse_submodules == RECURSE_SUBMODULES_OFF)\n+\t\tstrvec_push(argv, \"--recurse-submodules=no\");\n \tif (tags == TAGS_SET)\n \t\tstrvec_push(argv, \"--tags\");\n \telse if (tags == TAGS_UNSET)\n\nbut there are a bunch of other RECURSE_SUBMODULES_* values. I have no\nidea if any of those should be covered, too.\n\n-Peff\n"}]}