Skip to content

Commit a9a60b9

Browse files
Villemoesgitster
authored andcommitted
git.c: handle_alias: prepend alias info when first argument is -h
Most git commands respond to -h anywhere in the command line, or at least as a first and lone argument, by printing the usage information. For aliases, we can provide a little more information that might be useful in interpreting/understanding the following output by prepending a line telling that the command is an alias, and for what. When one invokes a simple alias, such as "cp = cherry-pick" with -h, this results in $ git cp -h 'cp' is aliased to 'cherry-pick' usage: git cherry-pick [<options>] <commit-ish>... ... When the alias consists of more than one word, this provides the additional benefit of informing the user which options are implicit in using the alias, e.g. with "cp = cherry-pick -n": $ git cp -h 'cp' is aliased to 'cherry-pick -n' usage: git cherry-pick [<options>] <commit-ish>... ... For shell commands, we cannot know how it responds to -h, but printing this line to stderr should not hurt, and can help in figuring out what is happening in a case like $ git sc -h 'sc' is aliased to '!somecommand' somecommand: invalid option '-h' Suggested-by: Jeff King <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6e76ba commit a9a60b9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

git.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ static int handle_alias(int *argcp, const char ***argv)
318318
alias_command = (*argv)[0];
319319
alias_string = alias_lookup(alias_command);
320320
if (alias_string) {
321+
if (*argcp > 1 && !strcmp((*argv)[1], "-h"))
322+
fprintf_ln(stderr, _("'%s' is aliased to '%s'"),
323+
alias_command, alias_string);
321324
if (alias_string[0] == '!') {
322325
struct child_process child = CHILD_PROCESS_INIT;
323326
int nongit_ok;

0 commit comments

Comments
 (0)