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

Re: [PATCH/RFC] sparse-checkout: take care of "--end-of-options" in set/add

From
Jeff King <peff@peff.net>
Date
Dec 21, 2023, 21:45 UTC
Message-ID
<20231221214550.GD1446091@coredump.intra.peff.net>
In-Reply-To
<xmqqsf3vmqug.fsf@gitster.g>
On Thu, Dec 21, 2023 at 09:02:15AM -0800, Junio C Hamano wrote:
Show 14 quoted lines
> > Yeah. I think it is in the same boat as the other two, in that I believe
> > that the KEEP_UNKNOWN_OPT flag is counter-productive and should just be
> > dropped.
> 
> If we dropped KEEP_UNKNOWN_OPT, however, the pattern that is
> currently accepted will stop working, e.g.,
> 
>  $ git sparse-checkout [add/set] --[no-]cone --foo bar
> 
> as we would barf with "--foo: unknown option", and the users who are
> used to this sloppy command line parsing we had for the past few
> years must now write "--end-of-options" before "--foo".  After all,
> the reason why the original authors of this code used KEEP_UNKNOWN
> is likely to deal with path patterns that begin with dashes.

Right, that is the "gotcha" I mentioned in my other email. Though that is the way it has behaved historically, my argument is that users are unreasonable to expect it to work:

  1. It is not consistent with the rest of Git commands.
  2. It is inconsistent with respect to existing options (and is an
     accident waiting to happen when new options are added).
So I'd consider it a bug-fix.
Show 11 quoted lines
> The patch in the message that started this thread may not be
> correct, either, I am afraid.  For either of these:
> 
>  $ git sparse-checkout [add/set] --[no-]cone foo --end-of-options bar
>  $ git sparse-checkout [add/set] --[no-]cone --foo --end-of-options bar
> 
> we would see that "foo" (or "--foo") is not "--end-of-options", and
> we end up using three patterns "foo" (or "--foo"),
> "--end-of-options", and "bar", I suspect.  I wonder if we should
> notice the "foo" or "--foo" that were not understood and error out,
> instead.

Yes, I agree that "--foo --end-of-options" should barf. And of course that happens naturally if you just let parse-options do its job by not passing the KEEP_UNKNOWN_OPT flag. ;)

I'm not sure about "foo". We do allow out-of-order options/args, so isn't it correct to keep it as a non-option argument?

Show 11 quoted lines
> But after all, it is not absolutely necessary to notice and barf.
> The ONLY practical use of the "--end-of-options" mechanism is to
> allow us to write (this applies to any git subcommand):
> 
>  #!/bin/sh
>  git cmd --hard --coded --options --end-of-options "$@"
> 
> in scripts to protect the intended operation from mistaking the
> end-user input as options.  And with a script written carefully to
> do so, all the args that appear before "--end-of-options" would be
> recognizable by the command line parser.

Yes, but if you misspell "--otpions", it magically becomes a parameter rather than having the command barf and complain. That is not the end of the world, but it is unfriendly and inconsistent with the rest of Git.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 19 in “sparse-checkout: take care of "--end-of-options" in set/add”
  1. sparse-checkout: take care of "--end-of-options" in set/addJunio C Hamano, Dec 20, 2023
  2. Josh SteadmonDec 20, 2023
  3. Junio C HamanoDec 21, 2023
  4. Jeff KingDec 21, 2023
  5. Junio C HamanoDec 21, 2023
  6. Jeff KingDec 21, 2023
  7. Junio C HamanoDec 21, 2023
  8. Jeff KingDec 23, 2023
  9. rsbecker@nexbridge.comDec 23, 2023
  10. Elijah NewrenDec 23, 2023
  11. Elijah NewrenDec 24, 2023
  12. archive: "--list" does not take further optionsJunio C Hamano, Dec 21, 2023
  13. René ScharfeDec 21, 2023
  14. Jeff KingDec 21, 2023
  15. Junio C HamanoDec 21, 2023
  16. Jeff KingDec 21, 2023
  17. Jeff KingDec 21, 2023
  18. Jeff KingDec 21, 2023
  19. Junio C HamanoDec 21, 2023

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.