git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pull: only pass '--recurse-submodules' to subcommands

From
Glen Choo <chooglen@google.com>
Date
May 10, 2022, 18:43 UTC
Message-ID
<kl6lzgjp6xeg.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<3234941c-5190-819f-fe3a-f528942c6b44@gmail.com>
Philippe Blain <levraiphilippeblain@gmail.com> writes:
Show 47 quoted lines
> Hi Glen,
>
> Le 2022-05-09 à 19:27, Glen Choo via GitGitGadget a écrit :
>> From: Glen Choo <chooglen@google.com>
>
> First, regarding the commit message title (I never know where to comment
> on that since I can't quote it :P)
>
>> Re: [PATCH] pull: only pass '--recurse-submodules' to subcommands
>
> I understand the intent, i.e. "only pass the CLI flag, not any config, to subcommands"
> but only because I already know what the patch is about. It could be
> read to mean "pass --recurse-submodules only to subcommands, and not to 
> something else". Since this is really a bug that affects the underlying 
> 'git fetch', maybe something like this ?
>
>     pull: pass '--recurse-submodules' to 'fetch' from CLI, not config
>
>> 
>> Fix a bug in "git pull" where `submodule.recurse` is preferred over
>> `fetch.recurseSubmodules` 
>
> here I would add "for the underlying 'git fetch'"
>
> (Documentation/config/fetch.txt says that
>> `fetch.recurseSubmodules` should be preferred.). Do this by passing the
>> value of the "--recurse-submodules" CLI option to the underlying fetch,
>> instead of passing a value that combines the CLI option and config
>> variables.
>> 
>> In other words, this bug occurred because builtin/pull.c is conflating
>> two similar-sounding, but different concepts:
>> 
>> - Whether "git pull" itself should care about submodules e.g. whether it
>>   should update the submodule worktrees after performing a merge.
>
> nit: "or rebase".
>
>> - The value of "--recurse-submodules" to pass to the underlying "git
>>   fetch".
>> 
>> Thus, when `submodule.recurse` is set, the underlying "git fetch" gets
>> invoked with "--recurse-submodules", overriding the value of
>> `fetch.recurseSubmodules`.
>
> the wording is a litlle bit misleading here, as submodule.recurse could
> be set to 'false', and then 'git fetch' will be invoked with '--recurse-submodules=false'.
Thanks for the wording suggestions :) I'll see what I can incorporate.
 
Show 11 quoted lines
>> An alternative (and more obvious) approach to fix the bug would be to
>> teach "git pull" to understand `fetch.recurseSubmodules`, but the
>> proposed solution works better because:
>> 
>> - We don't maintain two identical config-parsing implementions in "git
>>   pull" and "git fetch".
>> - It works better with other commands invoked by "git pull" e.g. "git
>>   merge" won't accidentally respect `fetch.recurseSubmodules`.
>
> I'm not sure of the meaning of the second bullet, since "git merge" should
> never perform a fetch ?... 

Ah, I'm describing a hypothetical issue with the 'obvious' (aka a literal reading of the docs) approach of teaching "git pull" to handle `fetch.recurseSubmodules`.

You are correct, "git merge" should never perform a fetch, so it shouldn't care about `fetch.recurseSubmodules`. But a careless 'fix' might be to copy what "git fetch" does with its config, e.g.

	if (!strcmp(k, "submodule.recurse")) {
		int r = git_config_bool(k, v) ?
			RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
		recurse_submodules = r;
	} else if (!strcmp(k, "fetch.recursesubmodules")) {
		recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
		return 0;
	}

which might make the internal "git merge" suddenly recurse into submodules. Of course, this can be fixed by using a fetch-specific variable, like:

	if (!strcmp(k, "submodule.recurse")) {
		int r = git_config_bool(k, v) ?
			RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
		recurse_submodules = r;
	}
  if (!strcmp(k, "fetch.recursesubmodules")) {
		fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
		return 0;
	}
  static int run_fetch(const char *repo, const char **refspecs)
  {
    /* ... */
    if (fetch_recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
       /* This is actually wrong wrt the docs, but assume that we could
       combine the two values here correctly. */
       recurse_submodules = fetch_recurse_submodules;
    if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
      switch (recurse_submodules) {
  }

but then we'd have to add more variables if we have `merge.recurseSubmodules`, or `rebase.recurseSubmodules` etc.

So the easiest way is to just tell "git pull" to stop assuming that it knows what the subcommands want :)

Previous: Glen ChooNext: Glen Choo via GitGitGadget
Message 6 of 15 in “pull: only pass '--recurse-submodules' to subcommands”
  1. pull: only pass '--recurse-submodules' to subcommandsGlen Choo via GitGitGadget, May 9, 2022
  2. Junio C HamanoMay 10, 2022
  3. Junio C HamanoMay 10, 2022
  4. Philippe BlainMay 10, 2022
  5. Glen ChooMay 10, 2022
  6. Glen ChooMay 10, 2022
  7. pull: only pass '--recurse-submodules' to subcommandsGlen Choo via GitGitGadget, May 10, 2022
  8. Philippe BlainMay 11, 2022
  9. Junio C HamanoMay 11, 2022
  10. Philippe BlainMay 11, 2022
  11. Glen ChooMay 11, 2022
  12. Junio C HamanoMay 12, 2022
  13. pull: do not let submodule.recurse override fetch.recurseSubmodulesGlen Choo via GitGitGadget, May 11, 2022
  14. Junio C HamanoMay 12, 2022
  15. Philippe BlainMay 12, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.