git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules
@ 2021-02-09 16:35 Dominick Latreille
  2021-02-09 17:00 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Dominick Latreille @ 2021-02-09 16:35 UTC (permalink / raw)
  To: git@vger.kernel.org

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules
  2021-02-09 16:35 The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules Dominick Latreille
@ 2021-02-09 17:00 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2021-02-09 17:00 UTC (permalink / raw)
  To: Dominick Latreille; +Cc: git@vger.kernel.org

On Tue, Feb 09, 2021 at 04:35:58PM +0000, Dominick Latreille wrote:

> 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-09 17:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 16:35 The argument "--recurse-submodules=no" when doing "fetch --all" is not passed to the following commands which can ends up fetching submodules Dominick Latreille
2021-02-09 17:00 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).