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

Re: [PATCH] clone: teach --single-branch and --branch during --recurse

From
Jeff King <peff@peff.net>
Date
Jan 9, 2020, 08:11 UTC
Message-ID
<20200109081150.GC3978837@coredump.intra.peff.net>
In-Reply-To
<20200108231900.192476-1-emilyshaffer@google.com>
On Wed, Jan 08, 2020 at 03:19:00PM -0800, Emily Shaffer wrote:
> Subject: clone: teach --single-branch and --branch during --recurse

A minor nit, but this subject confused me for a moment. I think we'd usually say "teach" for a new feature being implemented, and this is really just about passing along the existing features. Something like:

  clone: pass --single-branch and --branch when recursing submodules
would have been a bit more obvious (to me anyway).
> Previously, performing "git clone --recurse-submodules --single-branch"
> resulted in submodules cloning all branches even though the superproject
> cloned only one branch. Pipe --single-branch and its friend, --branch,
> through the submodule helper framework to make it to 'clone' later on.

Since I don't really use submodules, I don't have much data or even intuition to go on. But could this be a regression for some situations? E.g., imagine I have a repo "parent" whose branch "foo" has a submodule "child", but "child" only has a branch "bar". What happens now if I "git clone --recurse-submodules --single-branch -b foo parent", and what will happen after this patch?

I think it works before, but doesn't now.
Setting up like this:
  git init child
  (
  	cd child
  	git checkout -b bar
  	echo whatever >file
  	git add file
  	git commit -m 'child commit'
  )
  
  git init parent
  cd parent
  git checkout -b foo
  git submodule add $PWD/../child
  git commit -m 'add submodule'
if I use the current tip of master, I get:
  $ git clone --recurse-submodules --single-branch -b foo parent cur
  Cloning into 'cur'...
  done.
  Submodule 'child' (/home/peff/tmp/parent/../child) registered for path 'child'
  Cloning into '/home/peff/tmp/cur/child'...
  done.
  Submodule path 'child': checked out 'b5cbfcc9fec3b7d67e305468624fed2ba1aa4758'
  $ git -C cur/child log -1 --oneline | cat
  b5cbfcc child commit
with your patch, I get:
  $ git.compile clone --recurse-submodules --single-branch -b foo parent new
  Cloning into 'new'...
  done.
  Submodule 'child' (/home/peff/tmp/parent/../child) registered for path 'child'
  Cloning into '/home/peff/tmp/new/child'...
  warning: Could not find remote branch foo to clone.
  fatal: Remote branch foo not found in upstream origin
  fatal: clone of '/home/peff/tmp/parent/../child' into submodule path '/home/peff/tmp/new/child' failed
  Failed to clone 'child'. Retry scheduled
  Cloning into '/home/peff/tmp/new/child'...
  warning: Could not find remote branch foo to clone.
  fatal: Remote branch foo not found in upstream origin
  fatal: clone of '/home/peff/tmp/parent/../child' into submodule path '/home/peff/tmp/new/child' failed
  Failed to clone 'child' a second time, aborting
  $ git -C new/child log -1 --oneline | cat
  11acb3a add submodule
(there's nothing checked out in the submodule).

I have no idea how common this kind of thing would be, and I expect in most cases your patch would do what people want. But we might need to be better about retrying without those options when the first clone fails.

-Peff
Previous: Emily ShafferNext: Emily Shaffer
Message 3 of 22 in “clone: teach --single-branch and --branch during --recurse”
  1. clone: teach --single-branch and --branch during --recurseEmily Shaffer, Jan 8, 2020
  2. Emily ShafferJan 8, 2020
  3. Jeff KingJan 9, 2020
  4. Emily ShafferJan 16, 2020
  5. Jeff KingJan 17, 2020
  6. Emily ShafferJan 27, 2020
  7. Emily ShafferJan 27, 2020
  8. Jeff KingJan 27, 2020
  9. Emily ShafferJan 28, 2020
  10. Jeff KingJan 28, 2020
  11. Emily ShafferJan 28, 2020
  12. Jeff KingJan 27, 2020
  13. clone: pass --single-branch during --recurse-submodulesEmily Shaffer, Jan 28, 2020
  14. Jeff KingJan 30, 2020
  15. Emily ShafferFeb 21, 2020
  16. Jeff KingFeb 21, 2020
  17. 0/2 propagate --single-branch during clone --recurse-submodulesEmily Shaffer, Feb 21, 2020
  18. 1/2 submodule--helper: use C99 named initializerEmily Shaffer, Feb 21, 2020
  19. Jeff KingFeb 21, 2020
  20. Junio C HamanoFeb 22, 2020
  21. 2/2 clone: pass --single-branch during --recurse-submodulesEmily Shaffer, Feb 21, 2020
  22. Jeff KingFeb 21, 2020

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.