Skip to content

Commit 057ab54

Browse files
peffgitster
authored andcommitted
completion: fix multiple command removals
Commit 6532f37 ("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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 402e3e1 commit 057ab54

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ void list_cmds_by_config(struct string_list *list)
386386
const char *p = strchrnul(cmd_list, ' ');
387387

388388
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);
391391
else
392392
string_list_insert(list, sb.buf);
393393
strbuf_release(&sb);

t/t9902-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ test_expect_success 'git --help completion' '
14841484
test_completion "git --help core" "core-tutorial "
14851485
'
14861486

1487-
test_expect_failure 'completion.commands removes multiple commands' '
1487+
test_expect_success 'completion.commands removes multiple commands' '
14881488
test_config completion.commands "-cherry -mergetool" &&
14891489
git --list-cmds=list-mainporcelain,list-complete,config >out &&
14901490
! grep -E "^(cherry|mergetool)$" out

0 commit comments

Comments
 (0)