Skip to content

Commit 8893fd9

Browse files
peffgitster
authored andcommitted
git: add hidden --list-builtins option
It can be useful in the test suite to be able to iterate over the list of builtins. We could do this with some Makefile magic. But since the authoritative list is in the commands array inside git.c, and since this could also be handy for debugging, let's add a hidden command-line option to dump that list. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b48cbfc commit 8893fd9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

git.c

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static const char *env_names[] = {
2626
static char *orig_env[4];
2727
static int save_restore_env_balance;
2828

29+
static void list_builtins(void);
30+
2931
static void save_env_before_alias(void)
3032
{
3133
int i;
@@ -232,6 +234,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
232234
}
233235
(*argv)++;
234236
(*argc)--;
237+
} else if (!strcmp(cmd, "--list-builtins")) {
238+
list_builtins();
239+
exit(0);
235240
} else {
236241
fprintf(stderr, "Unknown option: %s\n", cmd);
237242
usage(git_usage_string);
@@ -529,6 +534,13 @@ int is_builtin(const char *s)
529534
return !!get_builtin(s);
530535
}
531536

537+
static void list_builtins(void)
538+
{
539+
int i;
540+
for (i = 0; i < ARRAY_SIZE(commands); i++)
541+
printf("%s\n", commands[i].cmd);
542+
}
543+
532544
#ifdef STRIP_EXTENSION
533545
static void strip_extension(const char **argv)
534546
{

0 commit comments

Comments
 (0)