Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.
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.
What's different between what you expected and what actually happened?
The usage indicates -h is the same as --heads, while -h is handled
upstream and always displays the usage of the command.
Anything else you want to add:
The same problem exists with the following commands:
grep -h is supposed to not show filenames according to its usage string.
show-ref -h is defined as some hidden option equivalent to --head.
Please review the rest of the bug report below.
You can delete any lines you don't wish to share.
[System Info]
git version:
git version 2.30.2
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.11.0-31-lowlatency #33-Ubuntu SMP PREEMPT Wed Aug 11 14:21:21 UTC 2021 x86_64
compiler info: gnuc: 10.2
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /bin/zsh
[Enabled Hooks]
not run from a git repository - no hooks to show
Since b92891f9783 (parseopt: add PARSE_OPT_NO_INTERNAL_HELP,
2009-03-08) parse_options() has handled "-h" unless told not to, so
when show-ref was migrated to parse_options() in
69932bc6117 (show-ref: migrate to parse-options, 2009-06-20) the
custom "-h" handling that was retained did nothing.
The option was then hidden in e62b3935056 (Show usage string for 'git
show-ref -h', 2009-11-09), but that OPT_BOOLEAN didn't do
anything. Let's just remove this dead code.
Reported-by: Ignacy Gawedzki <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
builtin/show-ref.c | 2 --
1 file changed, 2 deletions(-)
@@ -163,8 +163,6 @@ static const struct option show_ref_options[] = {OPT_BOOL(0,"heads",&heads_only,N_("only show heads (can be combined with tags)")),OPT_BOOL(0,"verify",&verify,N_("stricter reference checking, ""requires exact ref path")),-OPT_HIDDEN_BOOL('h',NULL,&show_head,-N_("show the HEAD reference, even if it would be filtered out")),OPT_BOOL(0,"head",&show_head,N_("show the HEAD reference, even if it would be filtered out")),OPT_BOOL('d',"dereference",&deref_tags,
The custom handling of the "-h" option was broken in
ba5f28bf79e (ls-remote: use parse-options api, 2016-01-19), first
released with Git v2.8.0. We've been promising that it's a synonym of
--head, but it's not.
We could make this work again by supplying the
PARSE_OPT_NO_INTERNAL_HELP flag to parse_options(), but if we were
writing this command today we wouldn't make this an exception. Since
it's been such a long time let's just remove this rather than
restoring the exception to "-h" handling.
Reported-by: Ignacy Gawedzki <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
Documentation/git-ls-remote.txt | 1 -
builtin/ls-remote.c | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
@@ -64,7 +64,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)N_("path of git-upload-pack on the remote host"),PARSE_OPT_HIDDEN},OPT_BIT('t',"tags",&flags,N_("limit to tags"),REF_TAGS),-OPT_BIT('h',"heads",&flags,N_("limit to heads"),REF_HEADS),+OPT_BIT(0,"heads",&flags,N_("limit to heads"),REF_HEADS),OPT_BIT(0,"refs",&flags,N_("do not show peeled tags"),REF_NORMAL),OPT_BOOL(0,"get-url",&get_url,N_("take url.<base>.insteadOf into account")),
The "grep" command supports both "-h" and "-H" options, along with a
mandatory pattern, but this has been partially usurped by the "-h"
handling in parse_options().
The reason it's just been "odd" instead of a bug is that we'll only
print out "-h" usage with parse_options() if there's no further
non-option arguments, so instead of printing this brief blurb on a
stand-alone -h we'd print out the full usage:
$ git grep -H
fatal: no pattern given
But for the aforementioned reason a "git grep -h <pattern>" would
work, we wouldn't take the !PARSE_OPT_NO_INTERNAL_HELP branch in
parse_options_step(), would handle our own custom 'h' option, and
builtin/grep.c itself would know what to do at that point.
Reported-by: Ignacy Gawedzki <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
builtin/grep.c | 3 ++-
t/t0012-help.sh | 4 +++-
t/t7810-grep.sh | 4 ++++
3 files changed, 9 insertions(+), 2 deletions(-)
From: SZEDER Gábor <hidden> Date: 2021-09-24 17:11:23
On Fri, Sep 24, 2021 at 06:51:45PM +0200, Ævar Arnfjörð Bjarmason wrote:
The custom handling of the "-h" option was broken in
ba5f28bf79e (ls-remote: use parse-options api, 2016-01-19), first
released with Git v2.8.0. We've been promising that it's a synonym of
--head, but it's not.
We could make this work again by supplying the
PARSE_OPT_NO_INTERNAL_HELP flag to parse_options(), but if we were
writing this command today we wouldn't make this an exception. Since
it's been such a long time let's just remove this rather than
restoring the exception to "-h" handling.
This breaks the case when '-h' is used in combination with a remote:
$ git ls-remote -h origin
225bc32a989d7a22fa6addafd4ce7dcd04675dbf refs/heads/maint
ddb1055343948e0d0bc81f8d20245f1ada6430a0 refs/heads/master
4c38ced6901a8523cea197b31b2616240ec9fb6e refs/heads/next
ee03ddbf0ea6a78ad9a229bd029408bbff85232e refs/heads/seen
687d33056ee28fd03567f3725150e3fcd0582979 refs/heads/todo
The description of this option contains the following:
Note that git ls-remote -h used without anything else on the command
line gives help, consistent with other git subcommands.
@@ -64,7 +64,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)N_("path of git-upload-pack on the remote host"),PARSE_OPT_HIDDEN},OPT_BIT('t',"tags",&flags,N_("limit to tags"),REF_TAGS),-OPT_BIT('h',"heads",&flags,N_("limit to heads"),REF_HEADS),+OPT_BIT(0,"heads",&flags,N_("limit to heads"),REF_HEADS),OPT_BIT(0,"refs",&flags,N_("do not show peeled tags"),REF_NORMAL),OPT_BOOL(0,"get-url",&get_url,N_("take url.<base>.insteadOf into account")),
The description of this option contains the following:
Note that git ls-remote -h used without anything else on the command
line gives help, consistent with other git subcommands.