Skip to content

Commit dbcb340

Browse files
committed
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 <johannes.schindelin@gmx.de>
1 parent 499f3f1 commit dbcb340

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
@@ -1067,6 +1067,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
10671067
{ "add untracked", run_add_untracked },
10681068
{ "patch", run_patch },
10691069
{ "diff", run_diff },
1070+
{ "quit", NULL },
10701071
{ "help", run_help },
10711072
};
10721073
struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
@@ -1118,17 +1119,22 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11181119
res = run_status(&s, ps, &files, &opts);
11191120

11201121
for (;;) {
1122+
struct command_item *util;
1123+
11211124
i = list_and_choose(&s, &commands, &main_loop_opts);
1122-
if (i == LIST_AND_CHOOSE_QUIT) {
1125+
if (i < 0 || i >= commands.items.nr)
1126+
util = NULL;
1127+
else
1128+
util = commands.items.items[i].util;
1129+
1130+
if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {
11231131
printf(_("Bye.\n"));
11241132
res = 0;
11251133
break;
11261134
}
1127-
if (i != LIST_AND_CHOOSE_ERROR) {
1128-
struct command_item *util =
1129-
commands.items.items[i].util;
1135+
1136+
if (util)
11301137
res = util->command(&s, ps, &files, &opts);
1131-
}
11321138
}
11331139

11341140
prefix_item_list_clear(&files);

0 commit comments

Comments
 (0)