Skip to content

Commit 161e895

Browse files
rscharfegitster
authored andcommitted
git: show alias info only with lone -h
Builtin commands show usage information on stdout if called with -h as their only option, usage.c::show_usage_if_asked() makes sure of that. Aliases show alias information on stderr if called with -h as the first option since a9a60b9 (git.c: handle_alias: prepend alias info when first argument is -h, 2018-10-09). This is surprising when using aliases for commands that take -h as a normal argument among others, like git grep. Tighten the condition and show the alias information only if -h is the only option given, to be consistent with builtins. It's probably still is a good idea to write to stderr, as an alias command doesn't have to be a builtin and could instead produce output with just -h that might be spoiled by an extra alias info line. Reported-by: Kevin Brodsky <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4ef048 commit 161e895

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static int handle_alias(struct strvec *args)
371371
alias_command = args->v[0];
372372
alias_string = alias_lookup(alias_command);
373373
if (alias_string) {
374-
if (args->nr > 1 && !strcmp(args->v[1], "-h"))
374+
if (args->nr == 2 && !strcmp(args->v[1], "-h"))
375375
fprintf_ln(stderr, _("'%s' is aliased to '%s'"),
376376
alias_command, alias_string);
377377
if (alias_string[0] == '!') {

0 commit comments

Comments
 (0)