Skip to content

Commit af74128

Browse files
ralfthgitster
authored andcommitted
help: introduce option --exclude-guides
Introduce option --exclude-guides to the help command. With this option being passed, "git help" will open man pages only for actual commands. Since we know it is a command, we can use function help_unknown_command to give the user advice on typos. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3b1c6a9 commit af74128

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

builtin/help.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ static int show_all = 0;
3737
static int show_guides = 0;
3838
static unsigned int colopts;
3939
static enum help_format help_format = HELP_FORMAT_NONE;
40+
static int exclude_guides;
4041
static struct option builtin_help_options[] = {
4142
OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
43+
OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")),
4244
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"),
@@ -426,10 +428,29 @@ static void list_common_guides_help(void)
426428
putchar('\n');
427429
}
428430

431+
static const char *check_git_cmd(const char* cmd)
432+
{
433+
char *alias;
434+
435+
if (is_git_command(cmd))
436+
return cmd;
437+
438+
alias = alias_lookup(cmd);
439+
if (alias) {
440+
printf_ln(_("`git %s' is aliased to `%s'"), cmd, alias);
441+
free(alias);
442+
exit(0);
443+
}
444+
445+
if (exclude_guides)
446+
return help_unknown_cmd(cmd);
447+
448+
return cmd;
449+
}
450+
429451
int cmd_help(int argc, const char **argv, const char *prefix)
430452
{
431453
int nongit;
432-
char *alias;
433454
enum help_format parsed_help_format;
434455

435456
argc = parse_options(argc, argv, prefix, builtin_help_options,
@@ -469,12 +490,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
469490
if (help_format == HELP_FORMAT_NONE)
470491
help_format = parse_help_format(DEFAULT_HELP_FORMAT);
471492

472-
alias = alias_lookup(argv[0]);
473-
if (alias && !is_git_command(argv[0])) {
474-
printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias);
475-
free(alias);
476-
return 0;
477-
}
493+
argv[0] = check_git_cmd(argv[0]);
478494

479495
switch (help_format) {
480496
case HELP_FORMAT_NONE:

t/t0012-help.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
test_description='help'
4+
5+
. ./test-lib.sh
6+
7+
configure_help () {
8+
test_config help.format html &&
9+
10+
# Unless the path has "://" in it, Git tries to make sure
11+
# the documentation directory locally exists. Avoid it as
12+
# we are only interested in seeing an attempt to correctly
13+
# invoke a help browser in this test.
14+
test_config help.htmlpath test://html &&
15+
16+
# Name a custom browser
17+
test_config browser.test.cmd ./test-browser &&
18+
test_config help.browser test
19+
}
20+
21+
test_expect_success "setup" '
22+
# Just write out which page gets requested
23+
write_script test-browser <<-\EOF
24+
echo "$*" >test-browser.log
25+
EOF
26+
'
27+
28+
test_expect_success "works for commands and guides by default" '
29+
configure_help &&
30+
git help status &&
31+
echo "test://html/git-status.html" >expect &&
32+
test_cmp expect test-browser.log &&
33+
git help revisions &&
34+
echo "test://html/gitrevisions.html" >expect &&
35+
test_cmp expect test-browser.log
36+
'
37+
38+
test_expect_success "--exclude-guides does not work for guides" '
39+
>test-browser.log &&
40+
test_must_fail git help --exclude-guides revisions &&
41+
test_must_be_empty test-browser.log
42+
'
43+
44+
test_done

0 commit comments

Comments
 (0)