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

Re: [PATCH 7/8] checkout: allow ignoring unmatched pathspec

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Dec 11, 2018, 22:36 UTC
Message-ID
<20181211223642.GU4883@hank.intra.tgummerer.com>
In-Reply-To
<CABPp-BG9vjXF-entmun4+dMoOsZdjMgotSOtUUeNxO8c2VwgXA@mail.gmail.com>
On 12/10, Elijah Newren wrote:
Show 65 quoted lines
> On Sun, Dec 9, 2018 at 12:05 PM Thomas Gummerer <t.gummerer@gmail.com> wrote:
> >
> > Currently when 'git checkout -- <pathspec>...' is invoked with
> > multiple pathspecs, where one or more of the pathspecs don't match
> > anything, checkout errors out.
> >
> > This can be inconvenient in some cases, such as when using git
> > checkout from a script.  Introduce a new --ignore-unmatched option,
> > which which allows us to ignore a non-matching pathspec instead of
> > erroring out.
> >
> > In a subsequent commit we're going to start using 'git checkout' in
> > 'git stash' and are going to make use of this feature.
> 
> This makes sense, but seems incomplete.  But to explain it, I think
> there's another bug I need to demonstrate first because it's related
> on builds on it.  First, the setup:
> 
>   $ echo foo >subdir/newfile
>   $ git add subdir/newfile
>   $ echo bar >>subdir/newfile
>   $ git status
>   On branch A
>   Changes to be committed:
>     (use "git reset HEAD <file>..." to unstage)
> 
>       new file:   subdir/newfile
> 
>   Changes not staged for commit:
>     (use "git add <file>..." to update what will be committed)
>     (use "git checkout -- <file>..." to discard changes in working directory)
> 
>       modified:   subdir/newfile
> 
> Now, does it do what we expect?
> 
>   $ git checkout HEAD -- subdir/newfile
>   error: pathspec 'subdir/newfile' did not match any file(s) known to git
> 
> This is the old overlay behavior; kinda lame, but you made no claims
> about fixing the default behavior.  What about with your new option?
> 
>   $ git checkout --no-overlay HEAD -- subdir
>   $ git status
>   On branch A
>   nothing to commit, working tree clean
> 
> Yes, the feature seems to work as advertised.  However, let's try
> again with a different variant:
> 
>   $ echo foo >subdir/newfile
>   $ git checkout --no-overlay HEAD -- subdir
>   $ git status
>   On branch A
>   Untracked files:
>     (use "git add <file>..." to include in what will be committed)
> 
>       subdir/newfile
> 
> Why is the file ignored and left there?  Also:
> 
>   $ git checkout --no-overlay HEAD -- subdir/newfile
>   error: pathspec 'subdir/newfile' did not match any file(s) known to git
> 
> That seems wrong to me.

Ah interesting, this is a case I didn't consider. I'm a bit torn on this one. My intention for the no overlay mode was that it would work similar to what I'd expect 'git reset --hard -- <pathspec>' to work if it existed, which means not removing untracked files if they exist.

While I think in the example you have above removing subdir/newfile may be the right behaviour I'm not so sure in the case of 'git checkout --no-overlay HEAD -- .' or ''git checkout --no-overlay HEAD -- t/*' for example. I don't think that should remove all untracked files in the repository or in the t/ directory. Removing untracked files in that case would probably surprise users more than your case above would.

I think it's okay to keep considering untracked files as special with respect to how they are treated by 'git checkout --no-overlay'.

Show 18 quoted lines
>                          The point of no-overlay is to make it match
> HEAD, and while subdir/newfile doesn't exist in HEAD or the index it
> does match in the working tree so the intent is clear. But let's say
> that the user did go ahead and specify your new flag:
> 
> 
>   $ git checkout --no-overlay --ignore-unmatch HEAD -- subdir/newfile
>   $ git status
>   On branch A
>   Untracked files:
>     (use "git add <file>..." to include in what will be committed)
> 
>       subdir/newfile
> 
>   nothing added to commit but untracked files present (use "git add" to track)
> 
> So now it avoids erroring out when the user does more work than
> necessary, but it still misses appropriately cleaning up the file.

Yeah this is a good point, this could be more confusing to the user than the previous case in my opinion. Maybe I'll just drop this patch for now (and the next one, as it's better to hold of until stash in C lands anyway), and then try to do all this in-core for 'git stash'.

Previous: Elijah NewrenNext: Thomas Gummerer
Message 70 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.