completion: fix multiple command removals
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>
Jeff King committed
Mar 20, 2019 at 14:03 UTC
057ab54b6646fbdabc8c953299f218081ff67456
2 files changed
+3
-3
help.c
+2
-2
@@ -386,8 +386,8 @@ void list_cmds_by_config(struct string_list *list)
386
const char *p = strchrnul(cmd_list, ' ');
387
388
strbuf_add(&sb, cmd_list, p - cmd_list);
389
- if (*cmd_list == '-')
390
- string_list_remove(list, cmd_list + 1, 0);
389
+ if (sb.buf[0] == '-')
390
+ string_list_remove(list, sb.buf + 1, 0);
391
else
392
string_list_insert(list, sb.buf);
393
strbuf_release(&sb);
t/t9902-completion.sh
+1
-1
@@ -1484,7 +1484,7 @@ test_expect_success 'git --help completion' '
1484
test_completion "git --help core" "core-tutorial "
1485
'
1486
1487
-test_expect_failure 'completion.commands removes multiple commands' '
1487
+test_expect_success 'completion.commands removes multiple commands' '
1488
test_config completion.commands "-cherry -mergetool" &&
1489
git --list-cmds=list-mainporcelain,list-complete,config >out &&
1490
! grep -E "^(cherry|mergetool)$" out