Skip to content

Commit 2850232

Browse files
committed
Merge branch 'tz/completion'
The completion helper code now pays attention to repository-local configuration (when available), which allows --list-cmds to honour a repository specific setting of completion.commands, for example. * tz/completion: completion: use __git when calling --list-cmds completion: fix multiple command removals t9902: test multiple removals via completion.commands git: read local config in --list-cmds
2 parents 08c9757 + 2eb6f09 commit 2850232

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ __git_all_commands=
10241024
__git_compute_all_commands ()
10251025
{
10261026
test -n "$__git_all_commands" ||
1027-
__git_all_commands=$(git --list-cmds=main,others,alias,nohelpers)
1027+
__git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
10281028
}
10291029

10301030
# Lists all set config variables starting with the given section prefix,
@@ -1652,9 +1652,9 @@ _git_help ()
16521652
esac
16531653
if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
16541654
then
1655-
__gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk"
1655+
__gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
16561656
else
1657-
__gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1657+
__gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
16581658
fi
16591659
}
16601660

@@ -2925,7 +2925,7 @@ __git_main ()
29252925
then
29262926
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
29272927
else
2928-
__gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
2928+
__gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
29292929
fi
29302930
;;
29312931
esac

git.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ static int list_cmds(const char *spec)
6262
{
6363
struct string_list list = STRING_LIST_INIT_DUP;
6464
int i;
65+
int nongit;
66+
67+
/*
68+
* Set up the repository so we can pick up any repo-level config (like
69+
* completion.commands).
70+
*/
71+
setup_git_directory_gently(&nongit);
6572

6673
while (*spec) {
6774
const char *sep = strchrnul(spec, ',');

help.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,6 @@ void list_cmds_by_config(struct string_list *list)
375375
{
376376
const char *cmd_list;
377377

378-
/*
379-
* There's no actual repository setup at this point (and even
380-
* if there is, we don't really care; only global config
381-
* matters). If we accidentally set up a repository, it's ok
382-
* too since the caller (git --list-cmds=) should exit shortly
383-
* anyway.
384-
*/
385378
if (git_config_get_string_const("completion.commands", &cmd_list))
386379
return;
387380

@@ -393,8 +386,8 @@ void list_cmds_by_config(struct string_list *list)
393386
const char *p = strchrnul(cmd_list, ' ');
394387

395388
strbuf_add(&sb, cmd_list, p - cmd_list);
396-
if (*cmd_list == '-')
397-
string_list_remove(list, cmd_list + 1, 0);
389+
if (sb.buf[0] == '-')
390+
string_list_remove(list, sb.buf + 1, 0);
398391
else
399392
string_list_insert(list, sb.buf);
400393
strbuf_release(&sb);

t/t9902-completion.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,12 @@ test_expect_success 'git --help completion' '
14841484
test_completion "git --help core" "core-tutorial "
14851485
'
14861486

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
1491+
'
1492+
14871493
test_expect_success 'setup for integration tests' '
14881494
echo content >file1 &&
14891495
echo more >file2 &&

0 commit comments

Comments
 (0)