threads / discuss / 55126

The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules

Subject: The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules

## tl;dr

2 messages between Feb 9, 2021 and Feb 9, 2021.

replies: 1people: 2as markdown or json

Dominick Latreille· Feb 9, 2021, 16:35 UTC · lore
Hi! 
I 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.

The git version I am using is the following: ``` git version 2.25.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 ``` Terminal used : Bash

Here is the command I ran to trigger this issue ``` GIT_TRACE2=1 git fetch --all --recurse-submodules=no ```

I expected the submodules to not be fetched and to see this command with traces activated ``` git fetch --append --no-auto-gc --recurse-submodules=no --no-write-commit-graph origin ```

But, here is the command line I got with traces activated and the submodules were fetched later on. ``` git fetch --append --no-auto-gc --no-write-commit-graph origin ```

Here are some repro steps with a repository on GitHub.
1. Clone with git bash https://github.com/DomLatr/RepoWithSubmodule
2.  In the repo, run the following command : "git submodule update --init"
3. 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.
3a. 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.
4. Run the command : "GIT_TRACE2=1 git fetch --all --recurse-submodules=no"
5. Notice that the submodules **are** fetched since it uses the default value "--recurse-submodules=on-demand" instead of the value passed in the CLI
It 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:

GIT_TRACE2=1 git fetch --all --recurse-submodules=no => git fetch --append --no-auto-gc --no-write-commit-graph origin

GIT_TRACE2=1 git fetch --all --recurse-submodules=on-demand => git fetch --append --no-auto-gc --no-write-commit-graph --recurse-submodules=on-demand origin

GIT_TRACE2=1 git fetch --all --recurse-submodules=yes => git fetch --append --no-auto-gc --no-write-commit-graph --recurse-submodules origin

Since 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.
Thanks!
Dominick
Jeff King· Feb 9, 2021, 17:00 UTC · re: Dominick Latreille · lore

Re: The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules

On Tue, Feb 09, 2021 at 04:35:58PM +0000, Dominick Latreille wrote:
Show 14 quoted lines
> Here is the command I ran to trigger this issue
> ```
> GIT_TRACE2=1 git fetch --all --recurse-submodules=no
> ```
> 
> I expected the submodules to not be fetched and to see this command with traces activated
> ```
> git fetch --append --no-auto-gc --recurse-submodules=no --no-write-commit-graph origin
> ```
> 
> But, here is the command line I got with traces activated and the submodules were fetched later on.
> ```
> git fetch --append --no-auto-gc --no-write-commit-graph origin
> ```

The issue is that "fetch --all" runs fetch sub-processes (one for each remote), and tries to copy its arguments to them. But it does so by looking at what it parsed and trying to recreate the relevant set of original arguments.

And it looks like when this was added way back in 7dce19d374 (fetch/pull: Add the --recurse-submodules option, 2010-11-12), it was not anticipated that somebody would need to turn recursion _off_. :) Of course it makes perfect sense if somebody later switches the default to on-demand. :)

So the solution is probably:
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 91f3d20696..cb59f79157 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1660,6 +1660,8 @@ static void add_options_to_argv(struct strvec *argv)
 		strvec_push(argv, "--recurse-submodules");
 	else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
 		strvec_push(argv, "--recurse-submodules=on-demand");
+	else if (recurse_submodules == RECURSE_SUBMODULES_OFF)
+		strvec_push(argv, "--recurse-submodules=no");
 	if (tags == TAGS_SET)
 		strvec_push(argv, "--tags");
 	else if (tags == TAGS_UNSET)

but there are a bunch of other RECURSE_SUBMODULES_* values. I have no
idea if any of those should be covered, too.

-Peff

← back to recent threads