# Tiny bug report, interaction between alias and help

7 messages from 2008-01-19 to 2008-01-22. Participants: François Pinard, Pascal Obry, Jeff King, Johannes Schindelin.
Thread: https://gitlist.dev/t/11675

## François Pinard, 2008-01-19 14:27

Subject: Tiny bug report, interaction between alias and help
Message-ID: <20080119142750.GA9182@phenix.progiciels-bpi.ca>
URL: https://gitlist.dev/e/20080119142750.GA9182%40phenix.progiciels-bpi.ca

```
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, 2008-01-19 15:23

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <479215D9.9020308@obry.net>
URL: https://gitlist.dev/e/479215D9.9020308%40obry.net
In-Reply-To: <20080119142750.GA9182@phenix.progiciels-bpi.ca>

```
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, 2008-01-19 17:41

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <20080119174146.GA3913@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080119174146.GA3913%40coredump.intra.peff.net
In-Reply-To: <20080119142750.GA9182@phenix.progiciels-bpi.ca>

```
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.

> 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, 2008-01-19 22:55

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <alpine.LSU.1.00.0801192252060.5731@racer.site>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0801192252060.5731%40racer.site
In-Reply-To: <20080119174146.GA3913@coredump.intra.peff.net>

```
Hi,

On Sat, 19 Jan 2008, Jeff King wrote:

> @@ -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, 2008-01-19 22:57

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <20080119225723.GA17170@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080119225723.GA17170%40coredump.intra.peff.net
In-Reply-To: <alpine.LSU.1.00.0801192252060.5731@racer.site>

```
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, 2008-01-19 23:23

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <alpine.LSU.1.00.0801192323040.5731@racer.site>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0801192323040.5731%40racer.site
In-Reply-To: <20080119225723.GA17170@coredump.intra.peff.net>

```
Hi,

On Sat, 19 Jan 2008, Jeff King wrote:

> 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, 2008-01-22 03:43

Subject: Re: Tiny bug report, interaction between alias and help
Message-ID: <20080122034329.GA1271@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080122034329.GA1271%40coredump.intra.peff.net
In-Reply-To: <fcaeb9bf0801200159k26303a18ned2eef8e6b5b65d2@mail.gmail.com>

```
On Sun, Jan 20, 2008 at 04:59:13PM +0700, Nguyen Thai Ngoc Duy wrote:

> 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

```
