help: respect aliases
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>
Jeff King committed
Feb 24, 2008 at 17:17 UTC
2156435ff22437909cda825f1901dceb198fef19
1 file changed
+32
-1
help.c
+32
-1
@@ -210,7 +210,7 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,
210
return longest;
211
}
212
213
-static void list_commands(void)
213
+static unsigned int load_command_list(void)
214
{
215
unsigned int longest = 0;
216
unsigned int len;
@@ -250,6 +250,14 @@ static void list_commands(void)
250
uniq(&other_cmds);
251
exclude_cmds(&other_cmds, &main_cmds);
252
253
+ return longest;
254
+}
255
+
256
+static void list_commands(void)
257
+{
258
+ unsigned int longest = load_command_list();
259
+ const char *exec_path = git_exec_path();
260
+
261
if (main_cmds.cnt) {
262
printf("available git commands in '%s'\n", exec_path);
263
printf("----------------------------");
@@ -284,6 +292,22 @@ void list_common_cmds_help(void)
292
}
293
}
294
295
+static int is_in_cmdlist(struct cmdnames *c, const char *s)
296
+{
297
+ int i;
298
+ for (i = 0; i < c->cnt; i++)
299
+ if (!strcmp(s, c->names[i]->name))
300
+ return 1;
301
+ return 0;
302
+}
303
+
304
+static int is_git_command(const char *s)
305
+{
306
+ load_command_list();
307
+ return is_in_cmdlist(&main_cmds, s) ||
308
+ is_in_cmdlist(&other_cmds, s);
309
+}
310
+
311
static const char *cmd_to_page(const char *git_cmd)
312
{
313
if (!git_cmd)
@@ -372,6 +396,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
396
int cmd_help(int argc, const char **argv, const char *prefix)
397
{
398
int nongit;
399
+ const char *alias;
400
401
setup_git_directory_gently(&nongit);
402
git_config(git_help_config);
@@ -391,6 +416,12 @@ int cmd_help(int argc, const char **argv, const char *prefix)
416
return 0;
417
}
418
419
+ alias = alias_lookup(argv[0]);
420
+ if (alias && !is_git_command(argv[0])) {
421
+ printf("`git %s' is aliased to `%s'\n", argv[0], alias);
422
+ return 0;
423
+ }
424
+
425
switch (help_format) {
426
case HELP_FORMAT_MAN:
427
show_man_page(argv[0]);