]> git.ipfire.org Git - thirdparty/git.git/commitdiff
built-in add -i: offer the `quit` command
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 29 Nov 2019 21:11:49 +0000 (21:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 1 Dec 2019 15:30:54 +0000 (07:30 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c

index 4d7d44a91757ce88af08de6945ab0720c4211b71..f395d54c08df577e557ef1590780c7e1f7c92296 100644 (file)
@@ -1071,6 +1071,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
                { "add untracked", run_add_untracked },
                { "patch", run_patch },
                { "diff", run_diff },
+               { "quit", NULL },
                { "help", run_help },
        };
        struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
@@ -1122,17 +1123,22 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
        res = run_status(&s, ps, &files, &opts);
 
        for (;;) {
+               struct command_item *util;
+
                i = list_and_choose(&s, &commands, &main_loop_opts);
-               if (i == LIST_AND_CHOOSE_QUIT) {
+               if (i < 0 || i >= commands.items.nr)
+                       util = NULL;
+               else
+                       util = commands.items.items[i].util;
+
+               if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {
                        printf(_("Bye.\n"));
                        res = 0;
                        break;
                }
-               if (i != LIST_AND_CHOOSE_ERROR) {
-                       struct command_item *util =
-                               commands.items.items[i].util;
+
+               if (util)
                        res = util->command(&s, ps, &files, &opts);
-               }
        }
 
        prefix_item_list_clear(&files);