completion: fix multiple command removals
authorJeff King <peff@peff.net>
Wed, 20 Mar 2019 18:03:28 +0000 (14:03 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Mar 2019 02:52:11 +0000 (11:52 +0900)
Commit 6532f3740b ("completion: allow to customize the completable
command list", 2018-05-20) tried to allow multiple space-separated
entries in completion.commands. To do this, it copies each parsed token
into a strbuf so that the result is NUL-terminated.

However, for tokens starting with "-", it accidentally passes the
original non-terminated string, meaning that only the final one worked.
Switch to using the strbuf.

Reported-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
help.c
t/t9902-completion.sh
diff --git a/help.c b/help.c
index fac7e421d01d40ee2c60c9d182c3f8305633683d..a9e451f2ee7a165eecb17746db9cc1a2f7e2cfbb 100644 (file)
--- a/help.c
+++ b/help.c
@@ -386,8 +386,8 @@ void list_cmds_by_config(struct string_list *list)
                const char *p = strchrnul(cmd_list, ' ');
 
                strbuf_add(&sb, cmd_list, p - cmd_list);
-               if (*cmd_list == '-')
-                       string_list_remove(list, cmd_list + 1, 0);
+               if (sb.buf[0] == '-')
+                       string_list_remove(list, sb.buf + 1, 0);
                else
                        string_list_insert(list, sb.buf);
                strbuf_release(&sb);
index 3d1859f303487b143bce13ebad4b91ec2626054f..43cf313a1c09ad8fb223ba775d5548c3f00c339c 100755 (executable)
@@ -1484,7 +1484,7 @@ test_expect_success 'git --help completion' '
        test_completion "git --help core" "core-tutorial "
 '
 
-test_expect_failure 'completion.commands removes multiple commands' '
+test_expect_success 'completion.commands removes multiple commands' '
        test_config completion.commands "-cherry -mergetool" &&
        git --list-cmds=list-mainporcelain,list-complete,config >out &&
        ! grep -E "^(cherry|mergetool)$" out