Skip to content

Commit

Permalink
help: respect aliases
Browse files Browse the repository at this point in the history
If we have an alias "foo" defined, then the help text for
"foo" (via "git help foo" or "git foo --help") now shows the
definition of the alias.

Before showing an alias definition, we make sure that there
is no git command which would override the alias (so that
even though you may have a "log" alias, even though it will
not work, we don't want to it supersede "git help log").

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 25, 2008
1 parent 9435111 commit 2156435
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,
return longest;
}

static void list_commands(void)
static unsigned int load_command_list(void)
{
unsigned int longest = 0;
unsigned int len;
Expand Down Expand Up @@ -250,6 +250,14 @@ static void list_commands(void)
uniq(&other_cmds);
exclude_cmds(&other_cmds, &main_cmds);

return longest;
}

static void list_commands(void)
{
unsigned int longest = load_command_list();
const char *exec_path = git_exec_path();

if (main_cmds.cnt) {
printf("available git commands in '%s'\n", exec_path);
printf("----------------------------");
Expand Down Expand Up @@ -284,6 +292,22 @@ void list_common_cmds_help(void)
}
}

static int is_in_cmdlist(struct cmdnames *c, const char *s)
{
int i;
for (i = 0; i < c->cnt; i++)
if (!strcmp(s, c->names[i]->name))
return 1;
return 0;
}

static int is_git_command(const char *s)
{
load_command_list();
return is_in_cmdlist(&main_cmds, s) ||
is_in_cmdlist(&other_cmds, s);
}

static const char *cmd_to_page(const char *git_cmd)
{
if (!git_cmd)
Expand Down Expand Up @@ -372,6 +396,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
int cmd_help(int argc, const char **argv, const char *prefix)
{
int nongit;
const char *alias;

setup_git_directory_gently(&nongit);
git_config(git_help_config);
Expand All @@ -391,6 +416,12 @@ int cmd_help(int argc, const char **argv, const char *prefix)
return 0;
}

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;
}

switch (help_format) {
case HELP_FORMAT_MAN:
show_man_page(argv[0]);
Expand Down

0 comments on commit 2156435

Please sign in to comment.