Skip to content

Commit b356993

Browse files
committed
Merge branch 'po/help-guides'
"git help" learned "-g" option to show the list of guides just like list of commands are given with "-a". * po/help-guides: doc: include --guide option description for "git help" help: mention -a and -g option, and 'git help <concept>' usage. builtin/help.c: add list_common_guides_help() function builtin/help.c: add --guide option builtin/help.c: split "-a" processing into two
2 parents fa7285d + a133737 commit b356993

File tree

3 files changed

+68
-10
lines changed

3 files changed

+68
-10
lines changed

Documentation/git-help.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,45 @@ git-help - Display help information about Git
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]
11+
'git help' [-a|--all] [-g|--guide]
12+
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
1213

1314
DESCRIPTION
1415
-----------
1516

16-
With no options and no COMMAND given, the synopsis of the 'git'
17+
With no options and no COMMAND or GUIDE given, the synopsis of the 'git'
1718
command and a list of the most commonly used Git commands are printed
1819
on the standard output.
1920

20-
If the option '--all' or '-a' is given, then all available commands are
21+
If the option '--all' or '-a' is given, all available commands are
2122
printed on the standard output.
2223

23-
If a Git subcommand is named, a manual page for that subcommand is brought
24-
up. The 'man' program is used by default for this purpose, but this
25-
can be overridden by other options or configuration variables.
24+
If the option '--guide' or '-g' is given, a list of the useful
25+
Git guides is also printed on the standard output.
26+
27+
If a command, or a guide, is given, a manual page for that command or
28+
guide is brought up. The 'man' program is used by default for this
29+
purpose, but this can be overridden by other options or configuration
30+
variables.
2631

2732
Note that `git --help ...` is identical to `git help ...` because the
2833
former is internally converted into the latter.
2934

35+
To display the linkgit:git[1] man page, use `git help git`.
36+
37+
This page can be displayed with 'git help help' or `git help --help`
38+
3039
OPTIONS
3140
-------
3241
-a::
3342
--all::
3443
Prints all the available commands on the standard output. This
35-
option supersedes any other option.
44+
option overrides any given command or guide name.
45+
46+
-g::
47+
--guides::
48+
Prints a list of useful guides on the standard output. This
49+
option overrides any given command or guide name.
3650

3751
-i::
3852
--info::

builtin/help.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ enum help_format {
3636
static const char *html_path;
3737

3838
static int show_all = 0;
39+
static int show_guides = 0;
3940
static unsigned int colopts;
4041
static enum help_format help_format = HELP_FORMAT_NONE;
4142
static struct option builtin_help_options[] = {
42-
OPT_BOOLEAN('a', "all", &show_all, N_("print all available commands")),
43+
OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
44+
OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")),
4345
OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
4446
OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
4547
HELP_FORMAT_WEB),
@@ -49,7 +51,7 @@ static struct option builtin_help_options[] = {
4951
};
5052

5153
static const char * const builtin_help_usage[] = {
52-
N_("git help [--all] [--man|--web|--info] [command]"),
54+
N_("git help [--all] [--guides] [--man|--web|--info] [command]"),
5355
NULL
5456
};
5557

@@ -413,6 +415,37 @@ static void show_html_page(const char *git_cmd)
413415
open_html(page_path.buf);
414416
}
415417

418+
static struct {
419+
const char *name;
420+
const char *help;
421+
} common_guides[] = {
422+
{ "attributes", "Defining attributes per path" },
423+
{ "glossary", "A Git glossary" },
424+
{ "ignore", "Specifies intentionally untracked files to ignore" },
425+
{ "modules", "Defining submodule properties" },
426+
{ "revisions", "Specifying revisions and ranges for Git" },
427+
{ "tutorial", "A tutorial introduction to Git (for version 1.5.1 or newer)" },
428+
{ "workflows", "An overview of recommended workflows with Git"},
429+
};
430+
431+
static void list_common_guides_help(void)
432+
{
433+
int i, longest = 0;
434+
435+
for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
436+
if (longest < strlen(common_guides[i].name))
437+
longest = strlen(common_guides[i].name);
438+
}
439+
440+
puts(_("The common Git guides are:\n"));
441+
for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
442+
printf(" %s ", common_guides[i].name);
443+
mput_char(' ', longest - strlen(common_guides[i].name));
444+
puts(_(common_guides[i].help));
445+
}
446+
putchar('\n');
447+
}
448+
416449
int cmd_help(int argc, const char **argv, const char *prefix)
417450
{
418451
int nongit;
@@ -428,7 +461,16 @@ int cmd_help(int argc, const char **argv, const char *prefix)
428461
git_config(git_help_config, NULL);
429462
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
430463
list_commands(colopts, &main_cmds, &other_cmds);
464+
}
465+
466+
if (show_guides)
467+
list_common_guides_help();
468+
469+
if (show_all || show_guides) {
431470
printf("%s\n", _(git_more_info_string));
471+
/*
472+
* We're done. Ignore any remaining args
473+
*/
432474
return 0;
433475
}
434476

git.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const char git_usage_string[] =
1313
" <command> [<args>]";
1414

1515
const char git_more_info_string[] =
16-
N_("See 'git help <command>' for more information on a specific command.");
16+
N_("'git help -a' and 'git help -g' lists available subcommands and some\n"
17+
"concept guides. See 'git help <command>' or 'git help <concept>'\n"
18+
"to read about a specific subcommand or concept.");
1719

1820
static struct startup_info git_startup_info;
1921
static int use_pager = -1;

0 commit comments

Comments
 (0)