threads / bug / 11675

Tiny bug report, interaction between alias and help

Subject: Tiny bug report, interaction between alias and help

## tl;dr

7 messages between Jan 19, 2008 and Jan 22, 2008.

replies: 6people: 4as markdown or json

François Pinard· Jan 19, 2008, 14:27 UTC · lore
Hi, git people.  (My first message here, please be kind!)

Page http://git.or.cz/#community says to report git bugs on this list. This is a tiny bug for "git version 1.5.4.rc3.14.g44397-dirty". If the "bug" is inappropriate, please then consider this as a suggestion! :-)

If, after "git config --global alias.st status", say, I try:
   git st --help
git then replies:
   No manual entry for git-st
It would be nice if --help was interacting better with aliases.
                                       Thanks for your attention,
-- 
François Pinard   http://pinard.progiciels-bpi.ca
Pascal Obry· Jan 19, 2008, 15:23 UTC · re: François Pinard · lore

Re: Tiny bug report, interaction between alias and help

François Pinard a écrit :
> It would be nice if --help was interacting better with aliases.

Agreed. I have myself been hit by this and thought it would be nice to have help looking at aliases if necessary.

Pascal.
-- 
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Jeff King· Jan 19, 2008, 17:41 UTC · re: François Pinard · lore

Re: Tiny bug report, interaction between alias and help

On Sat, Jan 19, 2008 at 09:27:50AM -0500, François Pinard wrote:
> Page http://git.or.cz/#community says to report git bugs on this list.
> This is a tiny bug for "git version 1.5.4.rc3.14.g44397-dirty".  If the
> "bug" is inappropriate, please then consider this as a suggestion!  :-)

I think it is more of a feature request than a bug, and as such should probably be dealt with post-1.5.4.

Show 9 quoted lines
> If, after "git config --global alias.st status", say, I try:
>
>   git st --help
>
> git then replies:
>
>   No manual entry for git-st
>
> It would be nice if --help was interacting better with aliases.

Maybe something like the following would be nicer. It would be a lot cleaner if the parsing were done by parseopt (which is hopefully going to happen post-1.5.4).

-- >8 -- help: print alias definitions

When asking for "git help alias", we unhelpfully just
tried to look for the manpage for "git-alias" which almost
certainly doesn't exist. Instead, let's print out the alias
definition.
---
 help.c |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/help.c b/help.c
index 1302a61..35176eb 100644
--- a/help.c
+++ b/help.c
@@ -334,6 +334,27 @@ static void show_html_page(const char *git_cmd)
 	execl_git_cmd("help--browse", page, NULL);
 }
 
+static const char *alias_help_cb_key;
+static char *alias_help_cb_value;
+static int alias_help_cb(const char *k, const char *v)
+{
+	if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_help_cb_key))
+		alias_help_cb_value = xstrdup(v);
+	return 0;
+}
+
+static int show_alias_help(const char *git_cmd)
+{
+	alias_help_cb_key = git_cmd;
+	alias_help_cb_value = NULL;
+	git_config(alias_help_cb);
+	if (!alias_help_cb_value)
+		return 0;
+	printf("`git %s' is aliased to `%s'\n", git_cmd, alias_help_cb_value);
+	free(alias_help_cb_value);
+	return 1;
+}
+
 void help_unknown_cmd(const char *cmd)
 {
 	fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
@@ -349,6 +370,9 @@ int cmd_version(int argc, const char **argv, const char *prefix)
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	const char *help_cmd = argv[1];
+	int nongit;
+
+	setup_git_directory_gently(&nongit);
 
 	if (argc < 2) {
 		printf("usage: %s\n\n", git_usage_string);
@@ -362,21 +386,30 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	}
 
 	else if (!strcmp(help_cmd, "--web") || !strcmp(help_cmd, "-w")) {
-		show_html_page(argc > 2 ? argv[2] : NULL);
+		const char *cmd = argc > 2 ? argv[2] : NULL;
+		if (cmd && show_alias_help(cmd))
+			return 0;
+		show_html_page(cmd);
 	}
 
 	else if (!strcmp(help_cmd, "--info") || !strcmp(help_cmd, "-i")) {
-		show_info_page(argc > 2 ? argv[2] : NULL);
+		const char *cmd = argc > 2 ? argv[2] : NULL;
+		if (cmd && show_alias_help(cmd))
+			return 0;
+		show_info_page(cmd);
 	}
 
 	else if (!strcmp(help_cmd, "--man") || !strcmp(help_cmd, "-m")) {
-		show_man_page(argc > 2 ? argv[2] : NULL);
+		const char *cmd = argc > 2 ? argv[2] : NULL;
+		if (cmd && show_alias_help(cmd))
+			return 0;
+		show_man_page(cmd);
 	}
 
 	else {
-		int nongit;
+		if (show_alias_help(help_cmd))
+			return 0;
 
-		setup_git_directory_gently(&nongit);
 		git_config(git_help_config);
 		if (help_default_format)
 			parse_help_format(help_default_format);
-- 
1.5.4.rc3.1129.g3e1ca-dirty
Johannes Schindelin· Jan 19, 2008, 22:55 UTC · re: Jeff King · lore

Re: Tiny bug report, interaction between alias and help

Hi,
On Sat, 19 Jan 2008, Jeff King wrote:
Show 38 quoted lines
> @@ -362,21 +386,30 @@ int cmd_help(int argc, const char **argv, const char *prefix)
>  	}
>  
>  	else if (!strcmp(help_cmd, "--web") || !strcmp(help_cmd, "-w")) {
> -		show_html_page(argc > 2 ? argv[2] : NULL);
> +		const char *cmd = argc > 2 ? argv[2] : NULL;
> +		if (cmd && show_alias_help(cmd))
> +			return 0;
> +		show_html_page(cmd);
>  	}
>  
>  	else if (!strcmp(help_cmd, "--info") || !strcmp(help_cmd, "-i")) {
> -		show_info_page(argc > 2 ? argv[2] : NULL);
> +		const char *cmd = argc > 2 ? argv[2] : NULL;
> +		if (cmd && show_alias_help(cmd))
> +			return 0;
> +		show_info_page(cmd);
>  	}
>  
>  	else if (!strcmp(help_cmd, "--man") || !strcmp(help_cmd, "-m")) {
> -		show_man_page(argc > 2 ? argv[2] : NULL);
> +		const char *cmd = argc > 2 ? argv[2] : NULL;
> +		if (cmd && show_alias_help(cmd))
> +			return 0;
> +		show_man_page(cmd);
>  	}
>  
>  	else {
> -		int nongit;
> +		if (show_alias_help(help_cmd))
> +			return 0;
>  
> -		setup_git_directory_gently(&nongit);
>  		git_config(git_help_config);
>  		if (help_default_format)
>  			parse_help_format(help_default_format);
> -- 
> 1.5.4.rc3.1129.g3e1ca-dirty

Urgh... We really have something like that in git? Looks like a prime candidate for refactoring a la

	void (*show_cmd)(const char *git_cmd) = show_man_page;
	const char *cmd = argc > 2 ? argv[2] : NULL;
	if (cmd && show_alias_help(cmd))
		return 0;
	if (!strcmp(help_cmd, "--web") || !strcmp(help_cmd, "-w"))
		show_cmd = show_html_page;
	else ...
		...
	show_cmd(cmd);

Ciao, Dscho

Jeff King· Jan 19, 2008, 22:57 UTC · re: Johannes Schindelin · lore

Re: Tiny bug report, interaction between alias and help

On Sat, Jan 19, 2008 at 10:55:24PM +0000, Johannes Schindelin wrote:
> Urgh... We really have something like that in git?  Looks like a prime 
> candidate for refactoring a la

Yes, my patch was a one-off "how about this?". I already have a refactored version in my tree (that also converts cmd_help to use parse_options), but I am holding on to it until post-1.5.4.

-Peff
Johannes Schindelin· Jan 19, 2008, 23:23 UTC · re: Jeff King · lore

Re: Tiny bug report, interaction between alias and help

Hi,
On Sat, 19 Jan 2008, Jeff King wrote:
Show 8 quoted lines
> On Sat, Jan 19, 2008 at 10:55:24PM +0000, Johannes Schindelin wrote:
> 
> > Urgh... We really have something like that in git?  Looks like a prime 
> > candidate for refactoring a la
> 
> Yes, my patch was a one-off "how about this?". I already have a 
> refactored version in my tree (that also converts cmd_help to use 
> parse_options), but I am holding on to it until post-1.5.4.
Very nice!

Thanks, Dscho

Jeff King· Jan 22, 2008, 03:43 UTC · lore

Re: Tiny bug report, interaction between alias and help

On Sun, Jan 20, 2008 at 04:59:13PM +0700, Nguyen Thai Ngoc Duy wrote:
Show 5 quoted lines
> I've been hit by this and came up with a similar approach as well. But
> I dropped it because it made aliases higher precedence than git-foo
> while git aliases cannot override git-foo (builtin or external ones).
> Is there any other way to make "git-help" respect git command
> executing order?

Yes, and that is an issue in my refactored patch as well. The tricky thing is that usually we say "try git-foo as a real git command, and then fall back to aliases" but we can't here, because "try git-foo" involves exec'ing something else.

It should be possible to do a lookup on "git-foo" and find out if it is a real git command, but I don't know how involved that will be. I'll look at it before I resend post-1.5.4.

And of course the other option is "so what?" People with alias.commit set will get the alias text rather than the man page. But they will quickly figure out that alias.commit doesn't actually _work_, and presumably remove it.

-Peff

← back to recent threads