threads / patch / 22702

patchshow help message also for aliased commands

Subject: [PATCH] show help message also for aliased commands

## tl;dr

3 messages between Feb 18, 2010 and Feb 18, 2010. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Patrick Sudowe· Feb 18, 2010, 01:29 UTC · lore
git help 'alias' currently only shows the actual git command
'alias' refers to. This patch changes the behavior so that
the help for the actual git command is shown. The user usually
knows the aliases defined, and sometimes its just more convenient
to type something like git help co than git help checkout
to find out about some rarely used option.
The original message is still there, so users do not face
unexpected or surprising behavior.
---
 builtin-help.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
Show changes to builtin-help.c +8 −4
diff --git a/builtin-help.c b/builtin-help.c
index 3182a2b..4d8906d 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -416,6 +416,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	int nongit;
 	const char *alias;
+	const char *cmd;
 	enum help_format parsed_help_format;
 	load_command_list("git-", &main_cmds, &other_cmds);
 
@@ -446,19 +447,22 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	alias = alias_lookup(argv[0]);
 	if (alias && !is_git_command(argv[0])) {
 		printf("`git %s' is aliased to `%s'\n", argv[0], alias);
-		return 0;
+		cmd = alias;
+	} else {
+		cmd = argv[0];
 	}
 
+
 	switch (help_format) {
 	case HELP_FORMAT_NONE:
 	case HELP_FORMAT_MAN:
-		show_man_page(argv[0]);
+		show_man_page(cmd);
 		break;
 	case HELP_FORMAT_INFO:
-		show_info_page(argv[0]);
+		show_info_page(cmd);
 		break;
 	case HELP_FORMAT_WEB:
-		show_html_page(argv[0]);
+		show_html_page(cmd);
 		break;
 	}
 
-- 
1.7.0
Junio C Hamano· Feb 18, 2010, 02:13 UTC · re: Patrick Sudowe · lore

Re: [PATCH] show help message also for aliased commands

Patrick Sudowe <patrick.sudowe@rwth-aachen.de> writes:
> git help 'alias' currently only shows the actual git command
> 'alias' refers to. This patch changes the behavior so that
> the help for the actual git command is shown.
I somehow think this is a horrible change.

I have "[alias] lg = log --oneline --no-merges" and I do appreciate that it tells the expansion, because I also have other similar ones like "[alias] lgm = log --notes-ref=amlog", "lgf", etc.

I don't want the expansion to be erased by manual page of "log"; typically the output from man is piped to less(1).

Besides, I may not know what "log" does, but at least I studied what options it takes when coming up with the hardcoded leading options already. I don't want to see the manual page of "log" by default when I ask git about "lg". If git tells me "lg" expands to "log --oneline", and I do not remember what other options "log" takes, I'll ask git myself about "log", not "lg".

Jeff King· Feb 18, 2010, 02:18 UTC · re: Patrick Sudowe · lore

Re: [PATCH] show help message also for aliased commands

On Thu, Feb 18, 2010 at 02:29:22AM +0100, Patrick Sudowe wrote:
Show 8 quoted lines
> git help 'alias' currently only shows the actual git command
> 'alias' refers to. This patch changes the behavior so that
> the help for the actual git command is shown. The user usually
> knows the aliases defined, and sometimes its just more convenient
> to type something like git help co than git help checkout
> to find out about some rarely used option.
> The original message is still there, so users do not face
> unexpected or surprising behavior.

Won't the original message get eaten when 'man' starts a pager (I know there are other, non-paged ways of showing the help, but man is the default).

Show 16 quoted lines
> @@ -446,19 +447,22 @@ int cmd_help(int argc, const char **argv, const char *prefix)
>  	alias = alias_lookup(argv[0]);
>  	if (alias && !is_git_command(argv[0])) {
>  		printf("`git %s' is aliased to `%s'\n", argv[0], alias);
> -		return 0;
> +		cmd = alias;
> +	} else {
> +		cmd = argv[0];
>  	}
>  
> +
>  	switch (help_format) {
>  	case HELP_FORMAT_NONE:
>  	case HELP_FORMAT_MAN:
> -		show_man_page(argv[0]);
> +		show_man_page(cmd);
This breaks horribly for all but the simplest of aliases. This works:
  $ git config alias.co checkout
  $ git help co
But this would need to trim it down to just "log":
  $ git config alias.lp 'log -p'
  $ git help lp
  `git lp' is aliased to `log -p'
  No manual entry for gitlog -p
And this is just impossible:
  $ git config alias.jive '!sh -c "git log | jive"'
  $ git help jive
  `git jive' is aliased to `!sh -c "git log | jive"'
  No manual entry for git!sh -c "git log | jive"
-Peff

← back to recent threads