Skip to content

Commit 0de7b03

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 465a969 commit 0de7b03

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

11211122
for (;;) {
1123+
struct command_item *util;
1124+
11221125
i = list_and_choose(&s, &commands, &main_loop_opts);
1123-
if (i == LIST_AND_CHOOSE_QUIT) {
1126+
if (i < 0 || i >= commands.items.nr)
1127+
util = NULL;
1128+
else
1129+
util = commands.items.items[i].util;
1130+
1131+
if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {
11241132
printf(_("Bye.\n"));
11251133
res = 0;
11261134
break;
11271135
}
1128-
if (i != LIST_AND_CHOOSE_ERROR) {
1129-
struct command_item *util =
1130-
commands.items.items[i].util;
1136+
1137+
if (util)
11311138
res = util->command(&s, ps, &files, &opts);
1132-
}
11331139
}
11341140

11351141
prefix_item_list_clear(&files);

0 commit comments

Comments
 (0)