Skip to content

Commit 2e697ce

Browse files
dschogitster
authored andcommitted
built-in add -i: offer the quit command
We do not really want to `exit()` here, of course, as this is safely libified code. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d763357 commit 2e697ce

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

add-interactive.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
10711071
{ "add untracked", run_add_untracked },
10721072
{ "patch", run_patch },
10731073
{ "diff", run_diff },
1074+
{ "quit", NULL },
10741075
{ "help", run_help },
10751076
};
10761077
struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
@@ -1122,17 +1123,22 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11221123
res = run_status(&s, ps, &files, &opts);
11231124

11241125
for (;;) {
1126+
struct command_item *util;
1127+
11251128
i = list_and_choose(&s, &commands, &main_loop_opts);
1126-
if (i == LIST_AND_CHOOSE_QUIT) {
1129+
if (i < 0 || i >= commands.items.nr)
1130+
util = NULL;
1131+
else
1132+
util = commands.items.items[i].util;
1133+
1134+
if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {
11271135
printf(_("Bye.\n"));
11281136
res = 0;
11291137
break;
11301138
}
1131-
if (i != LIST_AND_CHOOSE_ERROR) {
1132-
struct command_item *util =
1133-
commands.items.items[i].util;
1139+
1140+
if (util)
11341141
res = util->command(&s, ps, &files, &opts);
1135-
}
11361142
}
11371143

11381144
prefix_item_list_clear(&files);

0 commit comments

Comments
 (0)