git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] help: Add '--follow-alias' option

From
Namhyung Kim <namhyung.kim@lge.com>
Date
Mar 15, 2012, 02:52 UTC
Message-ID
<1331779969-8641-2-git-send-email-namhyung.kim@lge.com>
In-Reply-To
<1331779969-8641-1-git-send-email-namhyung.kim@lge.com>

The --follow-alias option will look up the alias definitions and use the first word as a command. For example, if I set my aliases as follows:

 $ git help br
 `git br' is aliased to `git branch'
 $ git help ru
 `git ru' is aliased to `git remote update'

adding --follow-alias (or -f) option will show man pages of git-branch and git-remote, respectively.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
---
 Documentation/git-help.txt |    7 ++++++-
 builtin/help.c             |   25 ++++++++++++++++++++-----
 2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
index 9e0b3f6..debf293 100644
--- a/Documentation/git-help.txt
+++ b/Documentation/git-help.txt
@@ -8,7 +8,7 @@ git-help - display help information about git
 SYNOPSIS
 --------
 [verse]
-'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]
+'git help' [-a|--all|-f|--follow-alias|-i|--info|-m|--man|-w|--web] [COMMAND]
 
 DESCRIPTION
 -----------
@@ -34,6 +34,11 @@ OPTIONS
 	Prints all the available commands on the standard output. This
 	option supersedes any other option.
 
+-f::
+--follow-alias::
+	Read alias definitions and use its first word as a command name
+	(if any).
+
 -i::
 --info::
 	Display manual page for the command in the 'info' format. The
diff --git a/builtin/help.c b/builtin/help.c
index f85c870..00392ea 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -30,9 +30,12 @@ enum help_format {
 };
 
 static int show_all = 0;
+static int follow_alias = 0;
 static enum help_format help_format = HELP_FORMAT_NONE;
 static struct option builtin_help_options[] = {
 	OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
+	OPT_BOOLEAN('f', "follow-alias", &follow_alias,
+			"follow alias to resolve command name"),
 	OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
 	OPT_SET_INT('w', "web", &help_format, "show manual in web browser",
 			HELP_FORMAT_WEB),
@@ -415,6 +418,7 @@ static void show_html_page(const char *git_cmd)
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	int nongit;
+	const char *cmd;
 	const char *alias;
 	enum help_format parsed_help_format;
 	load_command_list("git-", &main_cmds, &other_cmds);
@@ -443,22 +447,33 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	if (parsed_help_format != HELP_FORMAT_NONE)
 		help_format = parsed_help_format;
 
+	cmd = argv[0];
 	alias = alias_lookup(argv[0]);
 	if (alias && !is_git_command(argv[0])) {
-		printf("`git %s' is aliased to `git %s'\n", argv[0], alias);
-		return 0;
+		char *p;
+
+		if (!follow_alias) {
+			printf("`git %s' is aliased to `git %s'\n",
+			       argv[0], alias);
+			return 0;
+		}
+
+		p = strchr(alias, ' ');
+		if (p)
+			*p = '\0';
+		cmd = alias;
 	}
 
 	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.9
Previous: Namhyung KimNext: Junio C Hamano
Message 2 of 16 in “help: Fix help message for aliases”
  1. 1/3 help: Fix help message for aliasesNamhyung Kim, Mar 15, 2012
  2. 2/3 help: Add '--follow-alias' optionNamhyung Kim, Mar 15, 2012
  3. Junio C HamanoMar 15, 2012
  4. 김남형Mar 15, 2012
  5. Junio C HamanoMar 15, 2012
  6. Namhyung KimMar 15, 2012
  7. Junio C HamanoMar 15, 2012
  8. 3/3 help: Add 'help.follow-alias' config itemNamhyung Kim, Mar 15, 2012
  9. Junio C HamanoMar 15, 2012
  10. Namhyung KimMar 15, 2012
  11. Jeff KingMar 15, 2012
  12. 김남형Mar 15, 2012
  13. Jeff KingMar 15, 2012
  14. Junio C HamanoMar 15, 2012
  15. 김남형Mar 15, 2012
  16. Junio C HamanoMar 15, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.