From: Junio C Hamano <gitster@pobox.com>
To: Ian Wienand <iwienand@redhat.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] alias: pass --help through to shell alias
Date: Fri, 24 May 2024 17:34:55 -0700 [thread overview]
Message-ID: <xmqq8qzyk9u8.fsf@gitster.g> (raw)
In-Reply-To: <20240524070623.1344636-2-iwienand@redhat.com> (Ian Wienand's message of "Fri, 24 May 2024 17:04:14 +1000")
Ian Wienand <iwienand@redhat.com> writes:
> In trying to make some aliases more consistent in an internal tool, I
> implemented both -h/--help in the underlying command for a shell
> alias, and was a bit surprised when "git <alias> -h" worked but "git
> <alias> --help" didn't.
Yeah, with
alias.lg=log --oneline
alias.lgm=!sh -c 'GIT_NOTES_REF=refs/notes/amlog git log "$@" || :' -
"git lg -h" reports the alias, "git lg --help" does the same as "git
log --help", "git lgm -h" reports the alias, but "git lgm --help"
refrains from doing
sh -c 'GIT_NOTES_REF=refs/notes/amlog git log "$@" || :' - --help
and instead does the same as "git lgm -h" to report the alias.
This is a safe behaviour because the underlying command may not be
prepared to see "--help" and ignore it silently in the best case,
e.g.
sh -c 'false "$@" || :' - --help
that would confuse users by being totally silent, or
sh -c 'awk "$@" || :' - --help
that gives "awk: not an option: --help" (which is less useful than
the report of alias), or even worse yet, if the underlying command
does not understand "--help" and considers it something different,
who knows what havoc it would wreak.
For the above reason ...
> I would propose that "--help" to a shell alias is passed through to
> the underlying command. This way you can write aliases that act more
> like the other git commands.
... this is a dangerous thing to do unconditionally.
I wonder if we can come up with a notation to annotate aliases that
do support the "--help" option that wouldn't have been used by
mistake for existing aliases?
next prev parent reply other threads:[~2024-05-25 0:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 7:04 [PATCH] alias: pass --help through to shell alias Ian Wienand
2024-05-25 0:34 ` Junio C Hamano [this message]
2024-05-25 1:36 ` Ian Wienand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8qzyk9u8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=iwienand@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).