Re: Bug in git submodule update --remote
From: Philippe Blain <hidden>
Date: 2021-05-22 19:15:57
Hi Ben, Le 2021-05-19 à 10:41, Ben Avison a écrit :
On 19/05/2021 11:49, Atharva Raykar wrote:quoted
If I understood you correctly, you'd prefer that the updating of the submodule should be independent of the ref that is checked out in the submodule's directory. While I am not sure of the reason why the design of 'update --remote' uses the remote-tracking branch of the submodule, I can imagine adding a switch like 'submodule.<name>.remote' that defaults to 'origin'. Then the behaviour could be changed such that it always pulls from the remote specified in that option. This would help make the behaviour consistent in all the cases you mentioned, while also giving the option for a user to update the submodule from the remote of their choice (which may not be origin).I like that solution.
I also think a new config is a good solution.
Although, I should note that if the user has set submodule.<name>.remote to something other than 'origin', they will need to ensure that submodule.<name>.branch is also set, or they will still hit the "Unable to find current <remote>/HEAD revision in submodule" error that I initially stumbled on. How about an implementation like the following? I introduced a new "git submodule--helper" command rather than modify "print-default-remote" for a couple of reasons: 1) "print-default-remote" is also used for "git submodule sync" (I'm not sure if we should change its behaviour too) 2) "print-default-remote" needs to be executed from within the submodule, and takes no arguments, whereas I need to parse the superproject's .git/config so need to be executed from the superproject and take the submodule path as an argument The two functions I added are heavily based on "git submodule--helper remote-branch". However: * Unlike with the branch name, I don't fall back to using the name for the remote cached from when we read the .gitmodules file, if it isn't found in .git/config. It doesn't make sense to me for the .gitmodules file to include this information, as any new clones will only contain "origin" remotes anyway. * I removed "struct strbuf sb" since I don't think it's used. Ben
I think that we would want to careful examine every use of 'get_default_remote' (and the NEEDSWORK in submodule.c:get_next_submodule) and decide for each one if it makes sense to respect that new config before failing back to 'origin'. So I'm not sure about the approach here since it just fixes the behaviour for 'git submodule update --remote' but not other scenarios where the user would like another remote than 'origin' to be used for some operations in the submodule. There was also another bug report recently [1] around the new 'clone.defaultRemoteName' config and 'git submodule update --remote', so it might be good to also keep that in mind when working on a solution. Cheers, Philippe. P.S. I've CC'ed Emily who has plans for a big overhaul of submodule functionality over the next months [2] so might be interested. [1] https://lore.kernel.org/git/2d58fe40-9e8c-4653-8170-5411fd3cf6f4@www.fastmail.com/t/#u (local) [2] https://lore.kernel.org/git/0fc5c0f7-52f7-fb36-f654-ff5223a8809b@gmail.com/t/#u (local)