Skip to content

Commit 1ce5901

Browse files
avargitster
authored andcommitted
help: add --no-[external-commands|aliases] for use with --all
Add the ability to only emit git's own usage information under --all. This also allows us to extend the "test_section_spacing" tests added in a preceding commit to test "git help --all" output. Previously we could not do that, as the tests might find a git-* command in the "$PATH", which would make the output differ from one setup to another. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 503cdda commit 1ce5901

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

Documentation/git-help.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-help - Display help information about Git
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git help' [-a|--all] [--[no-]verbose]
11+
'git help' [-a|--all] [--[no-]verbose] [--[no-]external-commands] [--[no-]aliases]
1212
'git help' [[-i|--info] [-m|--man] [-w|--web]] [<command>|<guide>]
1313
'git help' [-g|--guides]
1414
'git help' [-c|--config]
@@ -48,6 +48,14 @@ OPTIONS
4848
--all::
4949
Prints all the available commands on the standard output.
5050

51+
--no-external-commands::
52+
When used with `--all`, exclude the listing of external "git-*"
53+
commands found in the `$PATH`.
54+
55+
--no-aliases::
56+
When used with `--all`, exclude the listing of configured
57+
aliases.
58+
5159
--verbose::
5260
When used with `--all` print description for all recognized
5361
commands. This is the default.

builtin/help.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ static const char *html_path;
5151
static int verbose = 1;
5252
static enum help_format help_format = HELP_FORMAT_NONE;
5353
static int exclude_guides;
54+
static int show_external_commands = -1;
55+
static int show_aliases = -1;
5456
static struct option builtin_help_options[] = {
5557
OPT_CMDMODE('a', "all", &cmd_mode, N_("print all available commands"),
5658
HELP_ACTION_ALL),
59+
OPT_BOOL(0, "external-commands", &show_external_commands,
60+
N_("show external commands in --all")),
61+
OPT_BOOL(0, "aliases", &show_aliases, N_("show aliases in --all")),
5762
OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")),
5863
OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
5964
OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
@@ -75,7 +80,7 @@ static struct option builtin_help_options[] = {
7580
};
7681

7782
static const char * const builtin_help_usage[] = {
78-
N_("git help [-a|--all] [--[no-]verbose]]"),
83+
N_("git help [-a|--all] [--[no-]verbose]] [--[no-]external-commands] [--[no-]aliases]"),
7984
N_("git help [[-i|--info] [-m|--man] [-w|--web]] [<command>]"),
8085
N_("git help [-g|--guides]"),
8186
N_("git help [-c|--config]"),
@@ -620,12 +625,19 @@ int cmd_help(int argc, const char **argv, const char *prefix)
620625
builtin_help_usage, 0);
621626
parsed_help_format = help_format;
622627

628+
if (cmd_mode != HELP_ACTION_ALL &&
629+
(show_external_commands >= 0 ||
630+
show_aliases >= 0))
631+
usage_msg_opt(_("the '--no-[external-commands|aliases]' options can only be used with '--all'"),
632+
builtin_help_usage, builtin_help_options);
633+
623634
switch (cmd_mode) {
624635
case HELP_ACTION_ALL:
625636
opt_mode_usage(argc, "--all", help_format);
626637
if (verbose) {
627638
setup_pager();
628-
list_all_cmds_help();
639+
list_all_cmds_help(show_external_commands,
640+
show_aliases);
629641
return 0;
630642
}
631643
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");

help.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,17 @@ static void list_all_cmds_help_aliases(int longest)
476476
string_list_clear(&alias_list, 1);
477477
}
478478

479-
void list_all_cmds_help(void)
479+
void list_all_cmds_help(int show_external_commands, int show_aliases)
480480
{
481481
int longest;
482482

483483
puts(_("See 'git help <command>' to read about a specific subcommand"));
484484
print_cmd_by_category(main_categories, &longest);
485485

486-
list_all_cmds_help_external_commands();
487-
list_all_cmds_help_aliases(longest);
486+
if (show_external_commands)
487+
list_all_cmds_help_external_commands();
488+
if (show_aliases)
489+
list_all_cmds_help_aliases(longest);
488490
}
489491

490492
int is_in_cmdlist(struct cmdnames *c, const char *s)

help.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static inline void mput_char(char c, unsigned int num)
2020
}
2121

2222
void list_common_cmds_help(void);
23-
void list_all_cmds_help(void);
23+
void list_all_cmds_help(int show_external_commands, int show_aliases);
2424
void list_guides_help(void);
2525

2626
void list_all_main_cmds(struct string_list *list);

t/t0012-help.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ do
5757
test_expect_code 129 git help $opt -m &&
5858
test_expect_code 129 git help $opt -w
5959
'
60+
61+
if test "$opt" = "-a"
62+
then
63+
continue
64+
fi
65+
66+
test_expect_success "invalid usage of '$opt' with --no-external-commands" '
67+
test_expect_code 129 git help $opt --no-external-commands
68+
'
69+
70+
test_expect_success "invalid usage of '$opt' with --no-aliases" '
71+
test_expect_code 129 git help $opt --no-external-commands
72+
'
6073
done
6174

6275
test_expect_success "works for commands and guides by default" '
@@ -187,6 +200,30 @@ do
187200
'
188201
done
189202

203+
test_expect_success "'git help -a' section spacing" '
204+
test_section_spacing \
205+
git help -a --no-external-commands --no-aliases <<-\EOF &&
206+
See '\''git help <command>'\'' to read about a specific subcommand
207+
208+
Main Porcelain Commands
209+
210+
Ancillary Commands / Manipulators
211+
212+
Ancillary Commands / Interrogators
213+
214+
Interacting with Others
215+
216+
Low-level Commands / Manipulators
217+
218+
Low-level Commands / Interrogators
219+
220+
Low-level Commands / Syncing Repositories
221+
222+
Low-level Commands / Internal Helpers
223+
EOF
224+
test_cmp expect actual
225+
'
226+
190227
test_expect_success "'git help -g' section spacing" '
191228
test_section_spacing_trailer git help -g <<-\EOF &&
192229

0 commit comments

Comments
 (0)