completion: let git provide the completable command list
Instead of maintaining a separate list of command classification, which often could go out of date, let's centralize the information back in git. While the function in git-completion.bash implies "list porcelain commands", that's not exactly what it does. It gets all commands (aka --list-cmds=main,others) then exclude certain non-porcelain ones. We could almost recreate this list two lists list-mainporcelain and others. The non-porcelain-but-included-anyway is added by the third category list-complete. Note that the current completion script incorrectly classifies filter-branch as porcelain and t9902 tests this behavior. We keep it this way in t9902 because this test does not really care which particular command is porcelain or plumbing, they're just names. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
fe902f2cef
commit
84a9713106
@ -47,12 +47,12 @@
|
|||||||
# command name category [category] [category]
|
# command name category [category] [category]
|
||||||
git-add mainporcelain worktree
|
git-add mainporcelain worktree
|
||||||
git-am mainporcelain
|
git-am mainporcelain
|
||||||
git-annotate ancillaryinterrogators
|
git-annotate ancillaryinterrogators complete
|
||||||
git-apply plumbingmanipulators
|
git-apply plumbingmanipulators complete
|
||||||
git-archimport foreignscminterface
|
git-archimport foreignscminterface
|
||||||
git-archive mainporcelain
|
git-archive mainporcelain
|
||||||
git-bisect mainporcelain info
|
git-bisect mainporcelain info
|
||||||
git-blame ancillaryinterrogators
|
git-blame ancillaryinterrogators complete
|
||||||
git-branch mainporcelain history
|
git-branch mainporcelain history
|
||||||
git-bundle mainporcelain
|
git-bundle mainporcelain
|
||||||
git-cat-file plumbinginterrogators
|
git-cat-file plumbinginterrogators
|
||||||
@ -62,7 +62,7 @@ git-check-mailmap purehelpers
|
|||||||
git-checkout mainporcelain history
|
git-checkout mainporcelain history
|
||||||
git-checkout-index plumbingmanipulators
|
git-checkout-index plumbingmanipulators
|
||||||
git-check-ref-format purehelpers
|
git-check-ref-format purehelpers
|
||||||
git-cherry ancillaryinterrogators
|
git-cherry ancillaryinterrogators complete
|
||||||
git-cherry-pick mainporcelain
|
git-cherry-pick mainporcelain
|
||||||
git-citool mainporcelain
|
git-citool mainporcelain
|
||||||
git-clean mainporcelain
|
git-clean mainporcelain
|
||||||
@ -70,7 +70,7 @@ git-clone mainporcelain init
|
|||||||
git-column purehelpers
|
git-column purehelpers
|
||||||
git-commit mainporcelain history
|
git-commit mainporcelain history
|
||||||
git-commit-tree plumbingmanipulators
|
git-commit-tree plumbingmanipulators
|
||||||
git-config ancillarymanipulators
|
git-config ancillarymanipulators complete
|
||||||
git-count-objects ancillaryinterrogators
|
git-count-objects ancillaryinterrogators
|
||||||
git-credential purehelpers
|
git-credential purehelpers
|
||||||
git-credential-cache purehelpers
|
git-credential-cache purehelpers
|
||||||
@ -84,30 +84,30 @@ git-diff mainporcelain history
|
|||||||
git-diff-files plumbinginterrogators
|
git-diff-files plumbinginterrogators
|
||||||
git-diff-index plumbinginterrogators
|
git-diff-index plumbinginterrogators
|
||||||
git-diff-tree plumbinginterrogators
|
git-diff-tree plumbinginterrogators
|
||||||
git-difftool ancillaryinterrogators
|
git-difftool ancillaryinterrogators complete
|
||||||
git-fast-export ancillarymanipulators
|
git-fast-export ancillarymanipulators
|
||||||
git-fast-import ancillarymanipulators
|
git-fast-import ancillarymanipulators
|
||||||
git-fetch mainporcelain remote
|
git-fetch mainporcelain remote
|
||||||
git-fetch-pack synchingrepositories
|
git-fetch-pack synchingrepositories
|
||||||
git-filter-branch ancillarymanipulators
|
git-filter-branch ancillarymanipulators complete
|
||||||
git-fmt-merge-msg purehelpers
|
git-fmt-merge-msg purehelpers
|
||||||
git-for-each-ref plumbinginterrogators
|
git-for-each-ref plumbinginterrogators
|
||||||
git-format-patch mainporcelain
|
git-format-patch mainporcelain
|
||||||
git-fsck ancillaryinterrogators
|
git-fsck ancillaryinterrogators complete
|
||||||
git-gc mainporcelain
|
git-gc mainporcelain
|
||||||
git-get-tar-commit-id ancillaryinterrogators
|
git-get-tar-commit-id ancillaryinterrogators complete
|
||||||
git-grep mainporcelain info
|
git-grep mainporcelain info
|
||||||
git-gui mainporcelain
|
git-gui mainporcelain
|
||||||
git-hash-object plumbingmanipulators
|
git-hash-object plumbingmanipulators
|
||||||
git-help ancillaryinterrogators
|
git-help ancillaryinterrogators complete
|
||||||
git-http-backend synchingrepositories
|
git-http-backend synchingrepositories
|
||||||
git-http-fetch synchelpers
|
git-http-fetch synchelpers
|
||||||
git-http-push synchelpers
|
git-http-push synchelpers
|
||||||
git-imap-send foreignscminterface
|
git-imap-send foreignscminterface complete
|
||||||
git-index-pack plumbingmanipulators
|
git-index-pack plumbingmanipulators
|
||||||
git-init mainporcelain init
|
git-init mainporcelain init
|
||||||
git-instaweb ancillaryinterrogators
|
git-instaweb ancillaryinterrogators complete
|
||||||
git-interpret-trailers purehelpers
|
git-interpret-trailers purehelpers complete
|
||||||
gitk mainporcelain
|
gitk mainporcelain
|
||||||
git-log mainporcelain info
|
git-log mainporcelain info
|
||||||
git-ls-files plumbinginterrogators
|
git-ls-files plumbinginterrogators
|
||||||
@ -120,14 +120,14 @@ git-merge-base plumbinginterrogators
|
|||||||
git-merge-file plumbingmanipulators
|
git-merge-file plumbingmanipulators
|
||||||
git-merge-index plumbingmanipulators
|
git-merge-index plumbingmanipulators
|
||||||
git-merge-one-file purehelpers
|
git-merge-one-file purehelpers
|
||||||
git-mergetool ancillarymanipulators
|
git-mergetool ancillarymanipulators complete
|
||||||
git-merge-tree ancillaryinterrogators
|
git-merge-tree ancillaryinterrogators
|
||||||
git-mktag plumbingmanipulators
|
git-mktag plumbingmanipulators
|
||||||
git-mktree plumbingmanipulators
|
git-mktree plumbingmanipulators
|
||||||
git-mv mainporcelain worktree
|
git-mv mainporcelain worktree
|
||||||
git-name-rev plumbinginterrogators
|
git-name-rev plumbinginterrogators complete
|
||||||
git-notes mainporcelain
|
git-notes mainporcelain
|
||||||
git-p4 foreignscminterface
|
git-p4 foreignscminterface complete
|
||||||
git-pack-objects plumbingmanipulators
|
git-pack-objects plumbingmanipulators
|
||||||
git-pack-redundant plumbinginterrogators
|
git-pack-redundant plumbinginterrogators
|
||||||
git-pack-refs ancillarymanipulators
|
git-pack-refs ancillarymanipulators
|
||||||
@ -141,32 +141,33 @@ git-quiltimport foreignscminterface
|
|||||||
git-read-tree plumbingmanipulators
|
git-read-tree plumbingmanipulators
|
||||||
git-rebase mainporcelain history
|
git-rebase mainporcelain history
|
||||||
git-receive-pack synchelpers
|
git-receive-pack synchelpers
|
||||||
git-reflog ancillarymanipulators
|
git-reflog ancillarymanipulators complete
|
||||||
git-remote ancillarymanipulators
|
git-remote ancillarymanipulators complete
|
||||||
git-repack ancillarymanipulators
|
git-repack ancillarymanipulators complete
|
||||||
git-replace ancillarymanipulators
|
git-replace ancillarymanipulators complete
|
||||||
git-request-pull foreignscminterface
|
git-request-pull foreignscminterface complete
|
||||||
git-rerere ancillaryinterrogators
|
git-rerere ancillaryinterrogators
|
||||||
git-reset mainporcelain worktree
|
git-reset mainporcelain worktree
|
||||||
git-revert mainporcelain
|
git-revert mainporcelain
|
||||||
git-rev-list plumbinginterrogators
|
git-rev-list plumbinginterrogators
|
||||||
git-rev-parse ancillaryinterrogators
|
git-rev-parse ancillaryinterrogators
|
||||||
git-rm mainporcelain worktree
|
git-rm mainporcelain worktree
|
||||||
git-send-email foreignscminterface
|
git-send-email foreignscminterface complete
|
||||||
git-send-pack synchingrepositories
|
git-send-pack synchingrepositories
|
||||||
git-shell synchelpers
|
git-shell synchelpers
|
||||||
git-shortlog mainporcelain
|
git-shortlog mainporcelain
|
||||||
git-show mainporcelain info
|
git-show mainporcelain info
|
||||||
git-show-branch ancillaryinterrogators
|
git-show-branch ancillaryinterrogators complete
|
||||||
git-show-index plumbinginterrogators
|
git-show-index plumbinginterrogators
|
||||||
git-show-ref plumbinginterrogators
|
git-show-ref plumbinginterrogators
|
||||||
git-sh-i18n purehelpers
|
git-sh-i18n purehelpers
|
||||||
git-sh-setup purehelpers
|
git-sh-setup purehelpers
|
||||||
git-stash mainporcelain
|
git-stash mainporcelain
|
||||||
|
git-stage complete
|
||||||
git-status mainporcelain info
|
git-status mainporcelain info
|
||||||
git-stripspace purehelpers
|
git-stripspace purehelpers
|
||||||
git-submodule mainporcelain
|
git-submodule mainporcelain
|
||||||
git-svn foreignscminterface
|
git-svn foreignscminterface complete
|
||||||
git-symbolic-ref plumbingmanipulators
|
git-symbolic-ref plumbingmanipulators
|
||||||
git-tag mainporcelain history
|
git-tag mainporcelain history
|
||||||
git-unpack-file plumbinginterrogators
|
git-unpack-file plumbinginterrogators
|
||||||
@ -177,11 +178,11 @@ git-update-server-info synchingrepositories
|
|||||||
git-upload-archive synchelpers
|
git-upload-archive synchelpers
|
||||||
git-upload-pack synchelpers
|
git-upload-pack synchelpers
|
||||||
git-var plumbinginterrogators
|
git-var plumbinginterrogators
|
||||||
git-verify-commit ancillaryinterrogators
|
git-verify-commit ancillaryinterrogators complete
|
||||||
git-verify-pack plumbinginterrogators
|
git-verify-pack plumbinginterrogators
|
||||||
git-verify-tag ancillaryinterrogators
|
git-verify-tag ancillaryinterrogators
|
||||||
gitweb ancillaryinterrogators
|
gitweb ancillaryinterrogators
|
||||||
git-whatchanged ancillaryinterrogators
|
git-whatchanged ancillaryinterrogators complete
|
||||||
git-worktree mainporcelain
|
git-worktree mainporcelain
|
||||||
git-write-tree plumbingmanipulators
|
git-write-tree plumbingmanipulators
|
||||||
gitattributes guide
|
gitattributes guide
|
||||||
|
@ -834,19 +834,33 @@ __git_complete_strategy ()
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# __git_commands requires 1 argument:
|
||||||
|
# 1: the command group, either "all" or "porcelain"
|
||||||
__git_commands () {
|
__git_commands () {
|
||||||
if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
|
case "$1" in
|
||||||
then
|
porcelain)
|
||||||
printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
|
if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
|
||||||
else
|
then
|
||||||
git --list-cmds=main,others
|
printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
|
||||||
fi
|
else
|
||||||
|
git --list-cmds=list-mainporcelain,others,list-complete
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
all)
|
||||||
|
if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
|
||||||
|
then
|
||||||
|
printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST"
|
||||||
|
else
|
||||||
|
git --list-cmds=main,others
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
__git_list_all_commands ()
|
__git_list_commands ()
|
||||||
{
|
{
|
||||||
local i IFS=" "$'\n'
|
local i IFS=" "$'\n'
|
||||||
for i in $(__git_commands)
|
for i in $(__git_commands $1)
|
||||||
do
|
do
|
||||||
case $i in
|
case $i in
|
||||||
*--*) : helper pattern;;
|
*--*) : helper pattern;;
|
||||||
@ -855,6 +869,11 @@ __git_list_all_commands ()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__git_list_all_commands ()
|
||||||
|
{
|
||||||
|
__git_list_commands all
|
||||||
|
}
|
||||||
|
|
||||||
__git_all_commands=
|
__git_all_commands=
|
||||||
__git_compute_all_commands ()
|
__git_compute_all_commands ()
|
||||||
{
|
{
|
||||||
@ -864,89 +883,7 @@ __git_compute_all_commands ()
|
|||||||
|
|
||||||
__git_list_porcelain_commands ()
|
__git_list_porcelain_commands ()
|
||||||
{
|
{
|
||||||
local i IFS=" "$'\n'
|
__git_list_commands porcelain
|
||||||
__git_compute_all_commands
|
|
||||||
for i in $__git_all_commands
|
|
||||||
do
|
|
||||||
case $i in
|
|
||||||
*--*) : helper pattern;;
|
|
||||||
applymbox) : ask gittus;;
|
|
||||||
applypatch) : ask gittus;;
|
|
||||||
archimport) : import;;
|
|
||||||
cat-file) : plumbing;;
|
|
||||||
check-attr) : plumbing;;
|
|
||||||
check-ignore) : plumbing;;
|
|
||||||
check-mailmap) : plumbing;;
|
|
||||||
check-ref-format) : plumbing;;
|
|
||||||
checkout-index) : plumbing;;
|
|
||||||
column) : internal helper;;
|
|
||||||
commit-tree) : plumbing;;
|
|
||||||
count-objects) : infrequent;;
|
|
||||||
credential) : credentials;;
|
|
||||||
credential-*) : credentials helper;;
|
|
||||||
cvsexportcommit) : export;;
|
|
||||||
cvsimport) : import;;
|
|
||||||
cvsserver) : daemon;;
|
|
||||||
daemon) : daemon;;
|
|
||||||
diff-files) : plumbing;;
|
|
||||||
diff-index) : plumbing;;
|
|
||||||
diff-tree) : plumbing;;
|
|
||||||
fast-import) : import;;
|
|
||||||
fast-export) : export;;
|
|
||||||
fsck-objects) : plumbing;;
|
|
||||||
fetch-pack) : plumbing;;
|
|
||||||
fmt-merge-msg) : plumbing;;
|
|
||||||
for-each-ref) : plumbing;;
|
|
||||||
hash-object) : plumbing;;
|
|
||||||
http-*) : transport;;
|
|
||||||
index-pack) : plumbing;;
|
|
||||||
init-db) : deprecated;;
|
|
||||||
local-fetch) : plumbing;;
|
|
||||||
ls-files) : plumbing;;
|
|
||||||
ls-remote) : plumbing;;
|
|
||||||
ls-tree) : plumbing;;
|
|
||||||
mailinfo) : plumbing;;
|
|
||||||
mailsplit) : plumbing;;
|
|
||||||
merge-*) : plumbing;;
|
|
||||||
mktree) : plumbing;;
|
|
||||||
mktag) : plumbing;;
|
|
||||||
pack-objects) : plumbing;;
|
|
||||||
pack-redundant) : plumbing;;
|
|
||||||
pack-refs) : plumbing;;
|
|
||||||
parse-remote) : plumbing;;
|
|
||||||
patch-id) : plumbing;;
|
|
||||||
prune) : plumbing;;
|
|
||||||
prune-packed) : plumbing;;
|
|
||||||
quiltimport) : import;;
|
|
||||||
read-tree) : plumbing;;
|
|
||||||
receive-pack) : plumbing;;
|
|
||||||
remote-*) : transport;;
|
|
||||||
rerere) : plumbing;;
|
|
||||||
rev-list) : plumbing;;
|
|
||||||
rev-parse) : plumbing;;
|
|
||||||
runstatus) : plumbing;;
|
|
||||||
sh-setup) : internal;;
|
|
||||||
shell) : daemon;;
|
|
||||||
show-ref) : plumbing;;
|
|
||||||
send-pack) : plumbing;;
|
|
||||||
show-index) : plumbing;;
|
|
||||||
ssh-*) : transport;;
|
|
||||||
stripspace) : plumbing;;
|
|
||||||
symbolic-ref) : plumbing;;
|
|
||||||
unpack-file) : plumbing;;
|
|
||||||
unpack-objects) : plumbing;;
|
|
||||||
update-index) : plumbing;;
|
|
||||||
update-ref) : plumbing;;
|
|
||||||
update-server-info) : daemon;;
|
|
||||||
upload-archive) : plumbing;;
|
|
||||||
upload-pack) : plumbing;;
|
|
||||||
write-tree) : plumbing;;
|
|
||||||
var) : infrequent;;
|
|
||||||
verify-pack) : infrequent;;
|
|
||||||
verify-tag) : plumbing;;
|
|
||||||
*) echo $i;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__git_porcelain_commands=
|
__git_porcelain_commands=
|
||||||
|
@ -13,7 +13,7 @@ complete ()
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Be careful when updating this list:
|
# Be careful when updating these lists:
|
||||||
#
|
#
|
||||||
# (1) The build tree may have build artifact from different branch, or
|
# (1) The build tree may have build artifact from different branch, or
|
||||||
# the user's $PATH may have a random executable that may begin
|
# the user's $PATH may have a random executable that may begin
|
||||||
@ -30,7 +30,8 @@ complete ()
|
|||||||
# completion for "git <TAB>", and a plumbing is excluded. "add",
|
# completion for "git <TAB>", and a plumbing is excluded. "add",
|
||||||
# "filter-branch" and "ls-files" are listed for this.
|
# "filter-branch" and "ls-files" are listed for this.
|
||||||
|
|
||||||
GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'
|
GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr filter-branch ls-files'
|
||||||
|
GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout filter-branch'
|
||||||
|
|
||||||
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
|
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user