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

Re: Wrong option -h in grep, ls-remote, and show-ref.

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 24, 2021, 18:12 UTC
Message-ID
<xmqqilypvo47.fsf@gitster.g>
In-Reply-To
<20210924141920.ezfpyf4uutob2h5z@zenon.in.qult.net>
Ignacy Gawedzki <ignacy.gawedzki@green-communications.fr> writes:
Show 11 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> git ls-remote -h
>
> What did you expect to happen? (Expected behavior)
>
> The same as git ls-remote --heads.
>
> What happened instead? (Actual behavior)
>
> Displayed the git ls-remote usage.
Thanks for a report, but this is very much working as intended.

There may be some subcommands that assign their own meaning to "-h" for historical reasons (like "ls-remote -h origin"), or for external reasons (like "grep -h -e pattern"), but most newbies expect a short help out of "-h" uniformly across subcommands.

Fortunately, "-h" alone would not make any sense for "grep" (you need a pattern) and you do not need to use "-h" for "ls-remote" [*]. We prioritized to help newbies by consistently giving a short help across subcommands, over letting "git grep -h" to complain "you need to give me a pattern", like so:

    $ git ls-remote --heads
    fatal: No remote configured to list refs from.
    $ git grep
    fatal: no pattern given
    $ git grep -h
    usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
    --cached              search in index instead of in the work tree
    ...
    $ git ls-remote -h
    usage: git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]
                         [-q | --quiet] [--exit-code] [--get-url]
    ...
HTH.
[Footnote]
* It is not end-user facing Porcelain, but is meant for scripting,
  and you can afford to write "--heads".  Besides, "-h" acts as
  "--heads" in "git ls-remote -h origin" or "git ls-remote -h -q"
  just fine.  Only the "-h and nothing else is given" case is
  sacrificed to help newbies in the case of this subcommand.
Previous: Ævar Arnfjörð Bjarmason
Message 12 of 12 in “Wrong option -h in grep, ls-remote, and show-ref.”
  1. Ignacy GawedzkiSep 24, 2021
  2. 0/3 show-ref, ls-remote, grep: fix -h handlingÆvar Arnfjörð Bjarmason, Sep 24, 2021
  3. 1/3 show-ref: remove unused custom handling of -hÆvar Arnfjörð Bjarmason, Sep 24, 2021
  4. Junio C HamanoSep 24, 2021
  5. René ScharfeSep 24, 2021
  6. Junio C HamanoSep 24, 2021
  7. 2/3 ls-remote: remove documentation for custom -h optionÆvar Arnfjörð Bjarmason, Sep 24, 2021
  8. SZEDER GáborSep 24, 2021
  9. Jeff KingSep 24, 2021
  10. Junio C HamanoSep 24, 2021
  11. 3/3 grep: pass PARSE_OPT_NO_INTERNAL_HELP, fix odd -h handlingÆvar Arnfjörð Bjarmason, Sep 24, 2021
  12. Junio C HamanoSep 24, 2021

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.