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
This commit is contained in:
Junio C Hamano 2019-04-16 19:28:09 +09:00
commit 2850232a21
4 changed files with 19 additions and 13 deletions

View File

@ -1024,7 +1024,7 @@ __git_all_commands=
__git_compute_all_commands ()
{
test -n "$__git_all_commands" ||
__git_all_commands=$(git --list-cmds=main,others,alias,nohelpers)
__git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
}
# Lists all set config variables starting with the given section prefix,
@ -1652,9 +1652,9 @@ _git_help ()
esac
if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
then
__gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk"
__gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
else
__gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk"
__gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
fi
}
@ -2925,7 +2925,7 @@ __git_main ()
then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else
__gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
__gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
fi
;;
esac

7
git.c
View File

@ -62,6 +62,13 @@ static int list_cmds(const char *spec)
{
struct string_list list = STRING_LIST_INIT_DUP;
int i;
int nongit;
/*
* Set up the repository so we can pick up any repo-level config (like
* completion.commands).
*/
setup_git_directory_gently(&nongit);
while (*spec) {
const char *sep = strchrnul(spec, ',');

11
help.c
View File

@ -375,13 +375,6 @@ void list_cmds_by_config(struct string_list *list)
{
const char *cmd_list;
/*
* There's no actual repository setup at this point (and even
* if there is, we don't really care; only global config
* matters). If we accidentally set up a repository, it's ok
* too since the caller (git --list-cmds=) should exit shortly
* anyway.
*/
if (git_config_get_string_const("completion.commands", &cmd_list))
return;
@ -393,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);

View File

@ -1484,6 +1484,12 @@ test_expect_success 'git --help completion' '
test_completion "git --help core" "core-tutorial "
'
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
'
test_expect_success 'setup for integration tests' '
echo content >file1 &&
echo more >file2 &&