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

Re: Regression `git checkout $rev -b branch` while in a `--no-checkout` clone does not check out files

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 3, 2019, 20:25 UTC
Message-ID
<xmqqef9th4iy.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CACsJy8C=O=ZDvD0ReSJOyAsNDEb5Yz-iFvs7oV5zAXaFf-dw5g@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
> I plan to revert this commit anyway when the new command "git
> switch-branch" comes. The optimization will be unconditionally in the
> new command without this hack and users are encouraged to use that one
> instead of "git checkout".

I tend to think that the behaviour is perfectly in line with what Ben wanted to have, which is to make "checkout -b new [HEAD]" not to touch anything in the index or the working tree at all.

It further is possible to argue that what is strange in the whole episode is what "clone --no-checkout" does. In such a repository, if you say "git status", you'd notice that it is reported that all paths have been deleted.

Now, if you instead do
	git clone $src dst
	cd dst
	git rm file
	git checkout -b new

i.e. starting from a clone with normal working tree, manually removing a path or two, and then create a new branch starting from that state while carrying all the local changes, you *do* want to see that 'file' to stay missing. After all, "do not lose the local changes; carry them forward" is what switching branches is about.

And from that point of view, we could consider that
	git clone --no-checkout $src $dst
is equivalent to
	git clone $src $dst && git -C $dst rm -r .
Having said all that.
> Meanwhile, let's see if Ben wants to fix this or revert it.

A "fix" to Ben's optimization for this particular case should be fairly straight-forward. I think we have a special case in the checkout codepath for an initial checkout and disable "carry forward the fact that the user wanted all the paths removed", so it would be the matter of adding yet another condition (is_cache_unborn(), which is used to set topts.initial_checkout) to the large collection of conditions in skip_merge_working_tree().

Back when the "optimization" was discussed, all reviewers said that it would become maintenance nightmare to ensure that the set of conditions accurately tracks the case where the optimization is safe. Now they are entitled to say "we told you so".

Previous: Duy NguyenNext: Anthony Sottile
Message 5 of 30 in “Regression `git checkout $rev -b branch` while in a `--no-checkout` clone does not check out files”
  1. Anthony SottileJan 1, 2019
  2. Duy NguyenJan 2, 2019
  3. Anthony SottileJan 2, 2019
  4. Duy NguyenJan 3, 2019
  5. Junio C HamanoJan 3, 2019
  6. Anthony SottileJan 3, 2019
  7. Junio C HamanoJan 3, 2019
  8. Anthony SottileJan 3, 2019
  9. Ben PeartJan 16, 2019
  10. 0/2 Fix regression in checkout -bBen Peart, Jan 18, 2019
  11. 1/2 checkout: add test to demonstrate regression with checkout -b on initial commitBen Peart, Jan 18, 2019
  12. SZEDER GáborJan 18, 2019
  13. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 18, 2019
  14. Junio C HamanoJan 18, 2019
  15. SZEDER GáborJan 19, 2019
  16. Junio C HamanoJan 19, 2019
  17. 0/2 Fix regression in checkout -bBen Peart, Jan 21, 2019
  18. 1/2 checkout: add test to demonstrate regression with checkout -b on initial commitBen Peart, Jan 21, 2019
  19. SZEDER GáborJan 23, 2019
  20. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 21, 2019
  21. Johannes SchindelinJan 22, 2019
  22. Junio C HamanoJan 22, 2019
  23. Jeff KingJan 22, 2019
  24. Junio C HamanoJan 22, 2019
  25. Ben PeartJan 22, 2019
  26. Junio C HamanoJan 23, 2019
  27. 0/2 Fix regression in checkout -bBen Peart, Jan 23, 2019
  28. 1/2 checkout: add test demonstrating regression with checkout -b on initial commitBen Peart, Jan 23, 2019
  29. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 23, 2019
  30. Junio C HamanoJan 23, 2019

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.