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

Re: [PATCH 0/8] introduce no-overlay and cached mode in git checkout

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Dec 11, 2018, 22:52 UTC
Message-ID
<20181211225241.GW4883@hank.intra.tgummerer.com>
In-Reply-To
<CABPp-BFaWtDiBPuGQVU_+VGQtDkemDKnvjHhz+h1sbUGssffmQ@mail.gmail.com>
On 12/10, Elijah Newren wrote:
Show 43 quoted lines
> On Sun, Dec 9, 2018 at 12:04 PM Thomas Gummerer <t.gummerer@gmail.com> wrote:
> >
> > Here's the series I mentioned a couple of times on the list already,
> > introducing a no-overlay mode in 'git checkout'.  The inspiration for
> > this came from Junios message in [*1*].
> >
> > Basically the idea is to also delete files when the match <pathspec>
> > in 'git checkout <tree-ish> -- <pathspec>' in the current tree, but
> > don't match <pathspec> in <tree-ish>.  The rest of the cases are
> > already properly taken care of by 'git checkout'.
> 
> Yes, but I'd put it a little differently:
> 
> """
> Basically, the idea is when the user run "git checkout --no-overlay
> <tree-ish> -- <pathspec>" that the given pathspecs should exactly
> match <tree-ish> after the operation completes.  This means that we
> also want to delete files that match <pathspec> if those paths are not
> found in <tree-ish>.
> """
> 
> ...and maybe even toss in some comments about the fact that this is
> the way git checkout should have always behaved, it just traditionally
> hasn't.  (You could also work in comments about how with this new mode
> the user can run git diff afterward with the given commit-ish and
> pathspecs and get back an empty diff, as expected, which wasn't true
> before.  But maybe I'm belaboring the point.)
> 
> 
> > The final step in the series is to actually make use of this in 'git
> > stash', which simplifies the code there a bit.  I am however happy to
> > hold off on this step until the stash-in-C series is merged, so we
> > don't delay that further.
> >
> > In addition to the no-overlay mode, we also add a --cached mode, which
> > works only on the index, thus similar to 'git reset <tree-ish> -- <pathspec>'.
> 
> If you're adding a --cached mode to make it only work on the index,
> should there be a similar mode to allow it to only work on the working
> tree?  (I'm not as concerned with that here, but I really think the
> new restore-files command by default should only operate on the
> working tree, and then have options to affect the index either in
> addition or instead of the working tree.)

Yeah I think that would be nice to have, though I'm not sure what we would name it in 'git checkout'. Maybe just having it in 'git restore-files' is good enough?

Show 44 quoted lines
> > Actually deprecating 'git reset <tree-ish> -- <pathspec>' should come
> > later, probably not before Duy's restore-files command lands, as 'git
> > checkout --no-overlay <tree-ish> -- <pathspec>' is a bit cumbersome to
> > type compared to 'git reset <tree-ish> -- <pathspec>'.
> 
> Makes sense.
> 
> > My hope is also that the no-overlay mode could become the new default
> > in the restore-files command Duy is currently working on.
> 
> Absolutely, yes.  I don't want another broken command.  :-)
> 
> 
> > No documentation yet, as I wanted to get this out for review first.
> > I'm not familiar with most of the code I touched here, so there may
> > well be much better ways to implement some of this, that I wasn't able
> > to figure out.  I'd be very happy with some feedback around that.
> >
> > Another thing I'm not sure about is how to deal with conflicts.  In
> > the cached mode this patch series is not dealing with it at all, as
> > 'git checkout -- <pathspec>' when pathspec matches a file with
> > conflicts doesn't update the index.  For the no-overlay mode, the file
> > is removed if the corresponding stage is not found in the index.  I'm
> > however not sure this is the right thing to do in all cases?
> 
> Here's how I'd go about analyzing that...
> 
> If the user passes a <tree-ish>, then the answer about what to do is
> pretty obvious; the <tree-ish> didn't have conflicts, so conflicted
> paths in the index that match the pathspec should be overwritten with
> whatever version of those paths existed in <tree-ish> (possibly
> implying deletion of some paths).
> 
> Also, as you point out, --cached means only modify the index and not
> the working tree; so if they specify both --cached and provide no
> tree, then they've specified a no-op.
> 
> So it's only interesting when you have conflicts in the index and
> specify --no-overlay without a <tree-ish> or --cached.  This boils
> down to "how do we update the working tree to match the index, when
> the index is conflicted?"  A couple points to consider:
>   * This is somewhat of an edge case
>   * In the normal case --no-overlay is only different from --overlay
> behavior for directories; it'd be nice if that extended to all cases

I'm not sure I follow what you mean here. How is --no-overlay different from --overlay with respect to directories? It's only different with respect to deletions, no?

Show 12 quoted lines
>   * How does this command behave without a <tree-ish> when
> --no-overlay is specified and a directory is given for a <pathspec>
> and there aren't any conflicts?  Are we being consistent with that
> behavior?
> 
> 
> However, I think it turns out that the answer is much simpler than all
> that initial analysis or what you say you've implemented.  Here's why:
> 
> If <pathspec> is a file which is present in both the working tree and
> the index and it has conflicts, then "git checkout -- <pathspec>" will
> currently throw an error:

I think what was missing from my original description, that actually makes it slightly more interesting from what you describe below is the '--ours' and '--theirs' flags in 'git checkout', with which one can check out a version of the file in the working tree. This is where it gets more interesting.

I think I got the right solution for that in patch 5, with deleting the file if it's deleted in "their" version and we pass --theirs to 'git checkout', and analogous for --ours. I was just wondering if there were any further edge cases that I can't think of right no.

Show 16 quoted lines
> $ git checkout -- subdir/counting
> error: path 'subdir/counting' is unmerged
> 
> In fact, even if every entry in subdir/ is a path that is in both the
> index and the working tree (so that --no-overlay and --overlay ought
> to behave the same), if any one of the files in subdir is conflicted,
> attempting to checkout the subdir will abort with this same error
> message and no paths will be updated at all:
> 
> $ git checkout -- subdir
> error: path 'subdir/counting' is unmerged
> 
> as such, the answer with what to do with --no-overlay mode is pretty
> clear: if the <pathspec> matches _any_ path that is conflicted, simply
> throw an error and abort the operation without making any changes at
> all.
Previous: Duy NguyenNext: Junio C Hamano
Message 78 of 115 in “introduce no-overlay and cached mode in git checkout”
  1. 0/8 introduce no-overlay and cached mode in git checkoutThomas Gummerer, Dec 9, 2018
  2. 1/8 move worktree tests to t24*Thomas Gummerer, Dec 9, 2018
  3. Junio C HamanoDec 10, 2018
  4. Duy NguyenDec 10, 2018
  5. Thomas GummererDec 11, 2018
  6. Eric SunshineDec 12, 2018
  7. Duy NguyenDec 12, 2018
  8. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Dec 9, 2018
  9. Duy NguyenDec 10, 2018
  10. Junio C HamanoDec 11, 2018
  11. Duy NguyenDec 12, 2018
  12. Junio C HamanoDec 12, 2018
  13. Elijah NewrenDec 10, 2018
  14. Thomas GummererDec 11, 2018
  15. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Dec 9, 2018
  16. Duy NguyenDec 10, 2018
  17. Elijah NewrenDec 10, 2018
  18. Duy NguyenDec 10, 2018
  19. Junio C HamanoDec 11, 2018
  20. Thomas GummererDec 20, 2018
  21. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Dec 9, 2018
  22. Duy NguyenDec 10, 2018
  23. Elijah NewrenDec 10, 2018
  24. Duy NguyenDec 10, 2018
  25. Elijah NewrenDec 10, 2018
  26. Duy NguyenDec 10, 2018
  27. Elijah NewrenDec 10, 2018
  28. Thomas GummererDec 11, 2018
  29. Junio C HamanoDec 11, 2018
  30. 5/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Dec 9, 2018
  31. Duy NguyenDec 10, 2018
  32. Thomas GummererDec 11, 2018
  33. Elijah NewrenDec 10, 2018
  34. Junio C HamanoDec 11, 2018
  35. Elijah NewrenDec 11, 2018
  36. Thomas GummererDec 11, 2018
  37. 6/8 checkout: add --cached optionThomas Gummerer, Dec 9, 2018
  38. Duy NguyenDec 10, 2018
  39. Junio C HamanoDec 11, 2018
  40. Elijah NewrenDec 11, 2018
  41. Duy NguyenDec 11, 2018
  42. Duy NguyenJan 31, 2019
  43. Junio C HamanoJan 31, 2019
  44. Duy NguyenFeb 1, 2019
  45. Junio C HamanoFeb 1, 2019
  46. Duy NguyenFeb 2, 2019
  47. Duy NguyenFeb 19, 2019
  48. Elijah NewrenFeb 19, 2019
  49. Duy NguyenFeb 19, 2019
  50. Junio C HamanoFeb 19, 2019
  51. Elijah NewrenFeb 19, 2019
  52. Junio C HamanoFeb 19, 2019
  53. Elijah NewrenFeb 19, 2019
  54. Duy NguyenFeb 20, 2019
  55. Junio C HamanoFeb 19, 2019
  56. Junio C HamanoFeb 19, 2019
  57. Elijah NewrenFeb 19, 2019
  58. Junio C HamanoFeb 19, 2019
  59. Duy NguyenFeb 20, 2019
  60. Duy NguyenFeb 20, 2019
  61. Duy NguyenFeb 20, 2019
  62. Elijah NewrenFeb 19, 2019
  63. Junio C HamanoFeb 19, 2019
  64. Elijah NewrenDec 10, 2018
  65. Thomas GummererDec 11, 2018
  66. 7/8 checkout: allow ignoring unmatched pathspecThomas Gummerer, Dec 9, 2018
  67. Duy NguyenDec 10, 2018
  68. Thomas GummererDec 11, 2018
  69. Elijah NewrenDec 10, 2018
  70. Thomas GummererDec 11, 2018
  71. 8/8 stash: use git checkout --no-overlayThomas Gummerer, Dec 9, 2018
  72. Elijah NewrenDec 10, 2018
  73. Junio C HamanoDec 10, 2018
  74. Thomas GummererDec 20, 2018
  75. Duy NguyenDec 10, 2018
  76. Elijah NewrenDec 10, 2018
  77. Duy NguyenDec 10, 2018
  78. Thomas GummererDec 11, 2018
  79. Junio C HamanoDec 12, 2018
  80. 0/8 introduce no-overlay mode in git checkoutThomas Gummerer, Dec 20, 2018
  81. 1/8 move worktree tests to t24*Thomas Gummerer, Dec 20, 2018
  82. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Dec 20, 2018
  83. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Dec 20, 2018
  84. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Dec 20, 2018
  85. 5/8 checkout: clarify commentThomas Gummerer, Dec 20, 2018
  86. 6/8 checkout: factor out mark_cache_entry_for_checkout functionThomas Gummerer, Dec 20, 2018
  87. 7/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Dec 20, 2018
  88. Duy NguyenDec 23, 2018
  89. Eric SunshineDec 23, 2018
  90. Thomas GummererJan 6, 2019
  91. 8/8 checkout: introduce checkout.overlayMode configThomas Gummerer, Dec 20, 2018
  92. Junio C HamanoJan 2, 2019
  93. Thomas GummererJan 6, 2019
  94. Junio C HamanoJan 7, 2019
  95. 0/8 introduce no-overlay mode in git checkoutThomas Gummerer, Jan 8, 2019
  96. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Jan 8, 2019
  97. 1/8 move worktree tests to t24*Thomas Gummerer, Jan 8, 2019
  98. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Jan 8, 2019
  99. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Jan 8, 2019
  100. 5/8 checkout: clarify commentThomas Gummerer, Jan 8, 2019
  101. 6/8 checkout: factor out mark_cache_entry_for_checkout functionThomas Gummerer, Jan 8, 2019
  102. 7/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Jan 8, 2019
  103. Jonathan NiederJan 22, 2019
  104. Junio C HamanoJan 23, 2019
  105. Thomas GummererJan 23, 2019
  106. Jonathan NiederJan 23, 2019
  107. Thomas GummererJan 24, 2019
  108. Junio C HamanoJan 23, 2019
  109. Jonathan NiederJan 24, 2019
  110. Thomas GummererJan 24, 2019
  111. Junio C HamanoJan 24, 2019
  112. Jonathan NiederJan 25, 2019
  113. Duy NguyenJan 25, 2019
  114. Philip OakleyFeb 9, 2019
  115. 8/8 checkout: introduce checkout.overlayMode configThomas Gummerer, Jan 8, 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.