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

Re: [RFC PATCH] git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of default

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 6, 2018, 20:21 UTC
Message-ID
<20180306202149.GA160269@aiede.svl.corp.google.com>
In-Reply-To
<1520366804-28233-1-git-send-email-eddy.petrisor@gmail.com>

(cc list snipped) Hi,

Eddy Petrișor wrote:
> Cc: [a lot of people]

Can you say a little about how this cc list was created? E.g. should "git send-email" get a feature to warn about long cc lists?

Show 14 quoted lines
> Signed-off-by: Eddy Petrișor <eddy.petrisor@gmail.com>
> ---
>
> There are projects such as llvm/clang which use several repositories, and they
> might be forked for providing support for various features such as adding Redox
> awareness to the toolchain. This typically means the superproject will use
> another branch than master, occasionally even use an old commit from that
> non-master branch.
>
> Combined with the fact that when incorporating such a hierachy of repositories
> usually the user is interested in just the exact commit specified in the
> submodule info, it follows that a desireable usecase is to be also able to
> provide '--depth 1' to avoid waiting for ages for the clone operation to
> finish.

Some previous discussion is at https://public-inbox.org/git/CAGZ79ka6UXKyVLmdLg_M5-sB1x96g8FRzRZy=ENy5aJBQf9_QA@mail.gmail.com/.

In theory this should be straightforward: Git protocol allows fetching an arbitrary commit, so "git submodule update" and similar commands could fetch the submodule commit by SHA-1 instead of by refname. Poof! Problem gone.

In practice, some complications:
 - some servers do not permit fetch-by-sha1.  For example, github does
   not permit it.  This is governed by the
   uploadpack.allowReachableSHA1InWant / uploadpack.allowAnySHA1InWant
   configuration items.
   That should be surmountable by making the behavior conditional, but
   it's a complication.
 - When the user passes --depth=<num>, do they mean that to apply to
   the superproject, to the submodules, or both?  Documentation should
   make the behavior clear.
   Fortunately I believe this complication has been takencare of using
   the --shallow-submodules option.
> Git submodule seems to be very stubborn and cloning master, although the
> wrapper script and the gitmodules-helper could work together to clone directly
> the branch specified in the .gitmodules file, if specified.

This could make sense. For the same reason as --depth in the superproject gives ambiguous signals about what should happen in submodules, --single-branch in the superproject gives ambiguous signals about what branch to fetch in submodules.

> Another wrinkle is that when the commit is not the tip of the branch, the depth
> parameter should somehow be stored in the .gitmodules info, but any change in
> the submodule will break the supermodule submodule depth info sooner or later,
> which is definitly frigile.

Hm, this seems to go in another direction. I don't think we should store the depth parameter in the .gitmodules file, since different users are likely to have different preferences about what to make shallow. If we make --depth easy enough to use at the superproject level then the user can specify what they want there.

Show 16 quoted lines
> I tried digging into this section of the code and debugging with bashdb to see
> where --depth might fit, but I got stuck on the shell-to-helper interaction and
> the details of the submodule implementation, so I want to lay out this first
> patch as starting point for the discussion in the hope somebody else picks it
> up or can provide some inputs. I have the feeling there are multiple code paths
> that are being ran, depending on the moment (initial clone, submodule
> recursive, post-clone update etc.) and I have a gut feeling there shouldn't be
> any code duplication just because the operation is different.
>
> This first patch is only trying to use a non-master branch, I have some changes
> for the --depth part, but I stopped working on it due to the "default depth"
> issue above.
>
> Does any of this sound reasonable?
> Is this patch idea usable or did I managed to touch the part of the code that
> should not be touched?

I agree with the goal. As mentioned above, I'm not confident about the particular mechanism --- e.g. something using fetch-by-sha1 seems likely to be more intuitive.

Today, the 'branch' setting in .gitmodules is only for "git submodule update --remote". This patch would be a significant expansion in scope for it. Hopefully others on the list can talk more about how that fits into various workflows and whether it would work out well.

Thanks and hope that helps, Jonathan

Show 20 quoted lines
>  git-submodule.sh | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 2491496..370f19e 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -589,8 +589,11 @@ cmd_update()
>  			branch=$(git submodule--helper remote-branch "$sm_path")
>  			if test -z "$nofetch"
>  			then
> +				# non-default branch
> +				rbranch=$(git config -f .gitmodules submodule.$sm_path.branch)
> +				br_refspec=${rbanch:+"refs/heads/$rbranch:refs/heads/$rbranch"}
>  				# Fetch remote before determining tracking $sha1
> -				fetch_in_submodule "$sm_path" $depth ||
> +				fetch_in_submodule "$sm_path" $depth $br_refspec ||
>  				die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
>  			fi
>  			remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
Next: Eddy Petrișor
Message 1 of 29 in “Re: [RFC PATCH] git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of default”
  1. Jonathan NiederMar 6, 2018
  2. Eddy PetrișorMar 8, 2018
  3. Eddy PetrișorMar 8, 2018
  4. Thomas GummererMar 16, 2018
  5. Eric SunshineMar 16, 2018
  6. Thomas GummererMar 17, 2018
  7. Eric SunshineMar 18, 2018
  8. Stefan BellerMar 26, 2018
  9. Fwd: [RFC PATCH] git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Mar 29, 2018
  10. Eddy PetrișorMar 29, 2018
  11. 1/2 git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Apr 3, 2018
  12. 2/2 t7406: add test for non-default branch in submoduleEddy Petrișor, Apr 3, 2018
  13. Eddy PetrișorApr 3, 2018
  14. Stefan BellerApr 4, 2018
  15. Eddy PetrișorApr 4, 2018
  16. Stefan BellerApr 4, 2018
  17. 1/9 git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Apr 18, 2018
  18. 2/9 t7406: add test for non-default branch in submoduleEddy Petrișor, Apr 18, 2018
  19. 3/9 fixup:t7406: use test_commit instead of echo/add/commit as suggested by Stefan BellerEddy Petrișor, Apr 18, 2018
  20. 5/9 fixup:t7406:cleanup chained submodules after test is doneEddy Petrișor, Apr 18, 2018
  21. 4/9 fixup:t7404:use 'git -C' instead of cd .. && gitEddy Petrișor, Apr 18, 2018
  22. 6/9 fixup:t7406:don't call init after add, is redundantEddy Petrișor, Apr 18, 2018
  23. 7/9 fixup:t7406:supr5 commit is done before submodules chainingEddy Petrișor, Apr 18, 2018
  24. 9/9 fixup:t7406:change branches in submodules after the link is doneEddy Petrișor, Apr 18, 2018
  25. 8/9 fixup:t7406:use super_w instead of the existing superEddy Petrișor, Apr 18, 2018
  26. Stefan BellerApr 18, 2018
  27. Eddy PetrișorApr 19, 2018
  28. Eddy PetrișorApr 19, 2018
  29. Stefan BellerApr 19, 2018

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.