Thread (5 messages) 5 messages, 3 authors, 2025-07-29

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

From: D. Ben Knoble <hidden>
Date: 2025-07-26 14:22:51

On Sat, Jul 26, 2025 at 9:12 AM D. Ben Knoble [off-list ref] wrote:
I have a few (unsent) patches I've been working on that touch the help
mechanism, so I have some thoughts below.

On Sat, Jul 26, 2025 at 4:13 AM Jeff King [off-list ref] wrote:
quoted
On Fri, Jul 25, 2025 at 04:52:40PM -0700, Junio C Hamano wrote:
quoted
When it redirects to our commands, it is less risky as we aim to
make all our commands honor a single "-h" via t0450.

   $ git -c alias.c=checkout c -h
   'c' is aliased to 'checkout'
   usage: git checkout [<options>] <branch>
      or: git checkout [<options>] [<branch>] -- <file>...

       -b <branch>           create and checkout a new branch
       -B <branch>           create/reset and checkout a branch
   ...
       --pathspec-from-file <file>
                             read pathspec from file
       --pathspec-file-nul   with --pathspec-from-file, pathspec elements are separated with NUL character

But then, it may not be such a good idea to pay attention to "do we
have extra '-h'?" when alias expands to our commands, e.g.
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.

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.
This is intriguing: it would mean that an alias is not purely a
textual replacement? That's true for ! aliases today, but other than
shelling out it's pretty close.
One other thing I've just remembered: "git help alias" shows the alias
information without running it. So I don't know if special-casing "-h"
adds much?

-- 
D. Ben Knoble
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help