git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Philippe Blain <levraiphilippeblain@gmail.com>
To: Huang Zou <huang.zou@schrodinger.com>, git@vger.kernel.org
Cc: Glen Choo <chooglen@google.com>
Subject: Re: Bug Report: fetch.recurseSubmodules doesn't affect git pull as otherwise stated in the git config docs
Date: Thu, 5 May 2022 19:57:53 -0400	[thread overview]
Message-ID: <fc492627-c552-10ec-b30c-820299241278@gmail.com> (raw)
In-Reply-To: <CAFnZ=JNE_Sa3TsKghBPj1d0cz3kc6o91Ogj-op8o6qK8t9hPgg@mail.gmail.com>

Hi Huang,

Le 2022-05-02 à 10:42, Huang Zou a écrit :
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> 1) Set the following configs:
>  git config submodule.recurse true
>  git config fetch.recurseSubmodules false
> 2) On a repo with submodules, run:
> git pull
> 
> What did you expect to happen? (Expected behavior)
> git pull doesn't recursively fetch submodules
> 
> What happened instead? (Actual behavior)
> Submodules are fetched recursively
> 
> What's different between what you expected and what actually happened?
> Submodules are fetched recursively
> 
> Anything else you want to add:
> git fetch works as intended. The documentation for fetch.recurseSubmodules
> states that "This option controls whether git fetch (and the underlying
> fetch in git pull)" so I would naturally expect git pull to behave the same
> as git fetch

I did not try to reproduce, but I took a look at the code and I think I understand
what happens. 

When 'git pull' invokes 'git fetch', it does so by specifically using the '--recurse-submodules'
flag, see [1]. It sends either 'yes', 'no' or 'on-demand' as value, depending on the value
of the local variable 'recurse_submodules'. This variable is initialized to the config value
of 'submodule.recurse' in 'git_pull_config' [2], called at [3], and then overwritten by the value given
explicitely on the command line [4], parsed at [5].

So when 'git fetch' runs when called by 'git pull', it always receive the 
'--recurse-submodules' flag, and thus any config for fetch.recurseSubmodules is ignored
(since explicit command line flags always have precedence over config values).

So one way to fix this would be to also parse 'fetch.recurseSubmodules' in 'git_pull_config',
and send the correct value to the 'git fetch' invocation... Or simpler, call 'git fetch' with
'--recurse-submodules-default' [9] instead...

[sidenote]
I'm thought for a while that it was maybe not a good idea to change the behaviour
in your specific situation. If you have 'submodule.recurse'
set to true and 'fetch.recurseSubmodules' set to false, and if the code is changed so that indeed
'git pull' does not fetch recursively, then the code will still try to update the submodule working
trees after the end of the operation (merge or rebase), see the end of 'cmd_pull' [6], [7]. This  is
OK, because if there are new submodule commits referenced by the superproject and they were not fetched because the 
fetch was not recursive, then the call to 'git submodule update' in update_submodules/rebase_submodule
should fetch them, so no problem there.
[/sidenote]

The bug also exists in other configurations, i.e. you could have 'submodule.recurse' 
set to 'false' or 'true' and 'fetch.recurseSubmodules' set to 'true' or 'on-demand' and then again
the 'git fetch' invocation would ignore the config value.  

So maybe a good way forward would be to change the flag to '--recurse-submodules-default' 
when invoking 'git fetch', so that the following configurations work as expected:
   - submodule.recurse=false / fetch.recurseSubmodules=true       (should fetch)
   - submodule.recurse=false / fetch.recurseSubmodules=on-demand  (should fetch if needed)
   - submodule.recurse=true  / fetch.recurseSubmodules=on-demand  (should fetch if needed)
   - submodule.recurse=true  / fetch.recurseSubmodules=false      (should not fetch)

I hope that helps.
Cheers,

Philippe.

[1] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L539-L551
[2] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L366-L369
[3] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L996
[4] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L122-L125
[5] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L1002
[6] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L1144-L1155
[7] https://github.com/git/git/blob/f5aaf72f1b5aeb3b77bccabce014ea2590e823e2/builtin/pull.c#L624-L648
[8] https://git-scm.com/docs/git-config#Documentation/git-config.txt-fetchrecurseSubmodules
[9] https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---recurse-submodules-defaultyeson-demand

  reply	other threads:[~2022-05-05 23:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 14:42 Bug Report: fetch.recurseSubmodules doesn't affect git pull as otherwise stated in the git config docs Huang Zou
2022-05-05 23:57 ` Philippe Blain [this message]
2022-05-06 21:50   ` Glen Choo
2022-05-06 22:24     ` Philippe Blain
2022-05-09 16:24       ` Huang Zou
2022-05-09 23:32 ` Glen Choo
2022-05-10  0:57   ` Philippe Blain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc492627-c552-10ec-b30c-820299241278@gmail.com \
    --to=levraiphilippeblain@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=huang.zou@schrodinger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).