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

Re: [RFC PATCH v1 0/1] ls-remote: inconsistency from the order of args and opts

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 14, 2022, 21:12 UTC
Message-ID
<YeHnT1BcisbVvQHB@camp.crustytoothpaste.net>
In-Reply-To
<220114.867db2rs0n.gmgdl@evledraar.gmail.com>
On 2022-01-14 at 19:57:17, Ævar Arnfjörð Bjarmason wrote:
Show 53 quoted lines
> 
> On Thu, Jan 13 2022, Junio C Hamano wrote:
> 
> > Teng Long <dyroneteng@gmail.com> writes:
> >
> >> +test_must_fail 'Exchange the order of "--heads" and <remote>' '
> >> +    git --version &&
> >> +    git init "test.git" &&
> >> +    test_commit -C "test.git" one &&
> >> +    git -C "test.git" ls-remote --heads ./. > result.1 &&
> >> +    git -C "test.git" ls-remote ./. --heads > result.2 &&
> >
> > I would say that this is working exactly as designed.  As with the
> > unix tradition, after the command name, first come options
> > (e.g. "--heads", "-v", etc. that begin with a dash or two dashes),
> > then arguments like "origin", "master", "." that are not dashed
> > options/flags.
> >
> > Then among the arguments, we generally take revs first and then
> > pathspecs.  "git help cli" explicitly mentions this, because it is
> > specific to "git" command suite, but it does not mention "dashed
> > options/flags first and then args", primarily because, at least back
> > when the documentation was written, this was taken as granted, iow,
> > those who wrote the "gitcli" documentation thought it was a common
> > knowledge among users that did not need to be spelled out.
> >
> > Apparently, it is not a common knowledge at least for you (and
> > probably others).  Perhaps we should add a paragraph to the cli help
> > and explicitly mention "options first and then args", before we go
> > on to say "among args, revs first and then pathspecs".
> 
> I don't think this summary is accurate.
> 
> We have multiple commands that are in GNU-fashion loose about whether
> you provide options first before no-option args, or after. E.g. we
> accept both of:
> 
>     git push --dry-run <remote> <ref>
> 
> And:
> 
>     git push <remote> <ref> --dry-run
> 
> The "tradition" you're referring to accurately summarizes how POSIX
> specifies that things should work.
>
> But when GNU came around its option parser was generally happy to accept
> options and args in either order. E.g. these both work with GNU
> coreutils, but the latter will fail on FreeBSD and various other
> capital-U UNIX-es:
> 
>     touch foo; rm -v foo
>     touch foo; rm foo -v

Yes, POSIX specifies this is how it should work because it avoids ambiguity. According to POSIX, -v is a file, and that's a valid name on Unix. If GNU rm fails to delete that file or provide a diagnostic about why it didn't, that's a bug.

In some cases, we do allow the GNU behavior of providing options anywhere on the command line, but we don't when it causes ambiguity, like in this case. I think we should document the current behavior, but I also think it's a given when working on Unix because many tools don't work that way. For example, test and find don't permit arbitrary location of options and arguments and they are found on all Unix systems. You can't write "test foo -f".

And to prove that this is ambiguous, I provide you the following example:

$ git update-ref refs/heads/--symref HEAD $ git ls-remote . --symref 1ffcbaa1a5f10c9f706314d77f88de20a4a498c2 refs/heads/--symref

That prints something very different if I write "git ls-remote --symref .". And it is actually the case that people write this kind of syntax in scripts relying on the current behavior and then those scripts get used in a variety of situations with arbitrary ref names, so this should continue to work this way. I believe a former employer may have these kinds of scripts, for example.

I'm not opposed to us building new tools which support the GNU behavior, but I don't think we should change tools where we have the existing behavior because it does lead to breakage in some scripting situations.

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 13 of 18 in “ls-remote: inconsistency from the order of args and opts”
  1. 0/1 ls-remote: inconsistency from the order of args and optsTeng Long, Jan 14, 2022
  2. 1/1 ls-remote: Make the output independent of the order of opts and <remote>Teng Long, Jan 14, 2022
  3. Junio C HamanoJan 14, 2022
  4. Junio C HamanoJan 14, 2022
  5. Teng LongJan 14, 2022
  6. Junio C HamanoJan 15, 2022
  7. Ævar Arnfjörð BjarmasonJan 14, 2022
  8. Junio C HamanoJan 14, 2022
  9. Ævar Arnfjörð BjarmasonJan 14, 2022
  10. Junio C HamanoJan 14, 2022
  11. Ævar Arnfjörð BjarmasonJan 15, 2022
  12. Junio C HamanoJan 15, 2022
  13. brian m. carlsonJan 14, 2022
  14. Ævar Arnfjörð BjarmasonJan 15, 2022
  15. Junio C HamanoJan 15, 2022
  16. Ævar Arnfjörð BjarmasonJan 15, 2022
  17. Junio C HamanoJan 15, 2022
  18. Teng LongJan 17, 2022

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.