git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "René Scharfe" <l.s.r@web.de>,
	"Kevin Brodsky" <kevin.brodsky@arm.com>,
	git@vger.kernel.org, "Rasmus Villemoes" <ravi@prevas.dk>
Subject: Re: [PATCH] git: show alias info only with lone -h
Date: Mon, 28 Jul 2025 06:43:16 -0700	[thread overview]
Message-ID: <xmqqfregzb0r.fsf@gitster.g> (raw)
In-Reply-To: <20250726081254.GA3042329@coredump.intra.peff.net> (Jeff King's message of "Sat, 26 Jul 2025 04:12:54 -0400")

Jeff King <peff@peff.net> writes:

> Another interesting case: even for our own commands, the alias itself
> may add extra arguments, which confuses things further. So:
>
>   $ git -c alias.gi='grep --cached' gi -h
>   'gi' is aliased to 'grep --cached'
>   fatal: no pattern given
>
> runs git-grep, but even though the user said only "-h" the alias added
> another option which prevents the help-mode from activating.
>
> In this case it is not too harmful, but you can come up with
> pathological cases where it actually runs a real command:
>
>   git -c alias.grep-for-foo='grep -e foo' grep-for-foo -h
>
> which runs a real grep.

Yes, that is an excellent point to further argue that we should fix
the help-alias case to stop there after describing the alias.  The
user can choose to do "git grep -h" and look for "--cached" after
learning that their 'git gi' is a shorthand for 'git grep --cached",
but we shouldn't be doing so.

> I guess one way to deal with it would be if the user runs "foo -h", and
> alias.foo is "bar --other arguments", then we run just "bar -h",
> dropping the extra arguments provided by the alias.

It is much simpler and saner to just stop after giving the alias
expansion, isn't it?  Nobody can get hurt if we did so; doing
anything else would be driving us into further corner cases that
would either confuse or harm the users.

> So IMHO the patch under discussion is a strict improvement, even though
> it leaves many other questionable cases unsolved.

That part I 100% agree with.  Let's accept the change, and then give
further fixes in related areas.

> I'd also be happy if on top we did:
>
>   1. When alias.foo="bar --options", turn "git foo -h" into "git bar
>      -h", dropping "--options".

This smells like piling more voodoo magic on top, which I am not
enthused.

>   2. When alias.foo="!bar", report only the alias and do not run "bar"
>      at all. The collateral damage here would be:
>
>         !git bar $(some_shell_magic_we_need)
>
>      but IMHO that is not all that bad. If we report the alias content,
>      the user can probably figure out which "git help" to run next.

This I very much like, and further, I would prefer to do this for
all aliases.

Thanks.

  parent reply	other threads:[~2025-07-28 13:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25  8:17 -h prints alias information even for grep Kevin Brodsky
2025-07-25 18:41 ` [PATCH] git: show alias info only with lone -h René Scharfe
2025-07-25 23:52   ` Junio C Hamano
2025-07-26  8:12     ` Jeff King
2025-07-26 13:12       ` D. Ben Knoble
2025-07-26 14:22         ` D. Ben Knoble
2025-07-29  7:23         ` Jeff King
2025-07-28 13:43       ` Junio C Hamano [this message]
2025-07-29  7:26         ` Jeff King

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=xmqqfregzb0r.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kevin.brodsky@arm.com \
    --cc=l.s.r@web.de \
    --cc=peff@peff.net \
    --cc=ravi@prevas.dk \
    /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).