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

Re: [PATCH] git: show alias info only with lone -h

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 28, 2025, 13:43 UTC
Message-ID
<xmqqfregzb0r.fsf@gitster.g>
In-Reply-To
<20250726081254.GA3042329@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 16 quoted lines
> 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.

Show 7 quoted lines
>   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.
Previous: Jeff KingNext: Jeff King
Message 8 of 9 in “-h prints alias information even for grep”
  1. Kevin BrodskyJul 25, 2025
  2. git: show alias info only with lone -hRené Scharfe, Jul 25, 2025
  3. Junio C HamanoJul 25, 2025
  4. Jeff KingJul 26, 2025
  5. D. Ben KnobleJul 26, 2025
  6. D. Ben KnobleJul 26, 2025
  7. Jeff KingJul 29, 2025
  8. Junio C HamanoJul 28, 2025
  9. Jeff KingJul 29, 2025

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.