Re: Bug Report: fetch.recurseSubmodules doesn't affect git pull as otherwise stated in the git config docs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux