Skip to content

Commit 84a9713

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe902f2 commit 84a9713

File tree

3 files changed

+58
-119
lines changed

3 files changed

+58
-119
lines changed

command-list.txt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
# command name category [category] [category]
4848
git-add mainporcelain worktree
4949
git-am mainporcelain
50-
git-annotate ancillaryinterrogators
51-
git-apply plumbingmanipulators
50+
git-annotate ancillaryinterrogators complete
51+
git-apply plumbingmanipulators complete
5252
git-archimport foreignscminterface
5353
git-archive mainporcelain
5454
git-bisect mainporcelain info
55-
git-blame ancillaryinterrogators
55+
git-blame ancillaryinterrogators complete
5656
git-branch mainporcelain history
5757
git-bundle mainporcelain
5858
git-cat-file plumbinginterrogators
@@ -62,15 +62,15 @@ git-check-mailmap purehelpers
6262
git-checkout mainporcelain history
6363
git-checkout-index plumbingmanipulators
6464
git-check-ref-format purehelpers
65-
git-cherry ancillaryinterrogators
65+
git-cherry ancillaryinterrogators complete
6666
git-cherry-pick mainporcelain
6767
git-citool mainporcelain
6868
git-clean mainporcelain
6969
git-clone mainporcelain init
7070
git-column purehelpers
7171
git-commit mainporcelain history
7272
git-commit-tree plumbingmanipulators
73-
git-config ancillarymanipulators
73+
git-config ancillarymanipulators complete
7474
git-count-objects ancillaryinterrogators
7575
git-credential purehelpers
7676
git-credential-cache purehelpers
@@ -84,30 +84,30 @@ git-diff mainporcelain history
8484
git-diff-files plumbinginterrogators
8585
git-diff-index plumbinginterrogators
8686
git-diff-tree plumbinginterrogators
87-
git-difftool ancillaryinterrogators
87+
git-difftool ancillaryinterrogators complete
8888
git-fast-export ancillarymanipulators
8989
git-fast-import ancillarymanipulators
9090
git-fetch mainporcelain remote
9191
git-fetch-pack synchingrepositories
92-
git-filter-branch ancillarymanipulators
92+
git-filter-branch ancillarymanipulators complete
9393
git-fmt-merge-msg purehelpers
9494
git-for-each-ref plumbinginterrogators
9595
git-format-patch mainporcelain
96-
git-fsck ancillaryinterrogators
96+
git-fsck ancillaryinterrogators complete
9797
git-gc mainporcelain
98-
git-get-tar-commit-id ancillaryinterrogators
98+
git-get-tar-commit-id ancillaryinterrogators complete
9999
git-grep mainporcelain info
100100
git-gui mainporcelain
101101
git-hash-object plumbingmanipulators
102-
git-help ancillaryinterrogators
102+
git-help ancillaryinterrogators complete
103103
git-http-backend synchingrepositories
104104
git-http-fetch synchelpers
105105
git-http-push synchelpers
106-
git-imap-send foreignscminterface
106+
git-imap-send foreignscminterface complete
107107
git-index-pack plumbingmanipulators
108108
git-init mainporcelain init
109-
git-instaweb ancillaryinterrogators
110-
git-interpret-trailers purehelpers
109+
git-instaweb ancillaryinterrogators complete
110+
git-interpret-trailers purehelpers complete
111111
gitk mainporcelain
112112
git-log mainporcelain info
113113
git-ls-files plumbinginterrogators
@@ -120,14 +120,14 @@ git-merge-base plumbinginterrogators
120120
git-merge-file plumbingmanipulators
121121
git-merge-index plumbingmanipulators
122122
git-merge-one-file purehelpers
123-
git-mergetool ancillarymanipulators
123+
git-mergetool ancillarymanipulators complete
124124
git-merge-tree ancillaryinterrogators
125125
git-mktag plumbingmanipulators
126126
git-mktree plumbingmanipulators
127127
git-mv mainporcelain worktree
128-
git-name-rev plumbinginterrogators
128+
git-name-rev plumbinginterrogators complete
129129
git-notes mainporcelain
130-
git-p4 foreignscminterface
130+
git-p4 foreignscminterface complete
131131
git-pack-objects plumbingmanipulators
132132
git-pack-redundant plumbinginterrogators
133133
git-pack-refs ancillarymanipulators
@@ -141,32 +141,33 @@ git-quiltimport foreignscminterface
141141
git-read-tree plumbingmanipulators
142142
git-rebase mainporcelain history
143143
git-receive-pack synchelpers
144-
git-reflog ancillarymanipulators
145-
git-remote ancillarymanipulators
146-
git-repack ancillarymanipulators
147-
git-replace ancillarymanipulators
148-
git-request-pull foreignscminterface
144+
git-reflog ancillarymanipulators complete
145+
git-remote ancillarymanipulators complete
146+
git-repack ancillarymanipulators complete
147+
git-replace ancillarymanipulators complete
148+
git-request-pull foreignscminterface complete
149149
git-rerere ancillaryinterrogators
150150
git-reset mainporcelain worktree
151151
git-revert mainporcelain
152152
git-rev-list plumbinginterrogators
153153
git-rev-parse ancillaryinterrogators
154154
git-rm mainporcelain worktree
155-
git-send-email foreignscminterface
155+
git-send-email foreignscminterface complete
156156
git-send-pack synchingrepositories
157157
git-shell synchelpers
158158
git-shortlog mainporcelain
159159
git-show mainporcelain info
160-
git-show-branch ancillaryinterrogators
160+
git-show-branch ancillaryinterrogators complete
161161
git-show-index plumbinginterrogators
162162
git-show-ref plumbinginterrogators
163163
git-sh-i18n purehelpers
164164
git-sh-setup purehelpers
165165
git-stash mainporcelain
166+
git-stage complete
166167
git-status mainporcelain info
167168
git-stripspace purehelpers
168169
git-submodule mainporcelain
169-
git-svn foreignscminterface
170+
git-svn foreignscminterface complete
170171
git-symbolic-ref plumbingmanipulators
171172
git-tag mainporcelain history
172173
git-unpack-file plumbinginterrogators
@@ -177,11 +178,11 @@ git-update-server-info synchingrepositories
177178
git-upload-archive synchelpers
178179
git-upload-pack synchelpers
179180
git-var plumbinginterrogators
180-
git-verify-commit ancillaryinterrogators
181+
git-verify-commit ancillaryinterrogators complete
181182
git-verify-pack plumbinginterrogators
182183
git-verify-tag ancillaryinterrogators
183184
gitweb ancillaryinterrogators
184-
git-whatchanged ancillaryinterrogators
185+
git-whatchanged ancillaryinterrogators complete
185186
git-worktree mainporcelain
186187
git-write-tree plumbingmanipulators
187188
gitattributes guide

contrib/completion/git-completion.bash

Lines changed: 28 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -834,19 +834,33 @@ __git_complete_strategy ()
834834
return 1
835835
}
836836

837+
# __git_commands requires 1 argument:
838+
# 1: the command group, either "all" or "porcelain"
837839
__git_commands () {
838-
if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
839-
then
840-
printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
841-
else
842-
git --list-cmds=main,others
843-
fi
840+
case "$1" in
841+
porcelain)
842+
if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
843+
then
844+
printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
845+
else
846+
git --list-cmds=list-mainporcelain,others,list-complete
847+
fi
848+
;;
849+
all)
850+
if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
851+
then
852+
printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST"
853+
else
854+
git --list-cmds=main,others
855+
fi
856+
;;
857+
esac
844858
}
845859

846-
__git_list_all_commands ()
860+
__git_list_commands ()
847861
{
848862
local i IFS=" "$'\n'
849-
for i in $(__git_commands)
863+
for i in $(__git_commands $1)
850864
do
851865
case $i in
852866
*--*) : helper pattern;;
@@ -855,6 +869,11 @@ __git_list_all_commands ()
855869
done
856870
}
857871

872+
__git_list_all_commands ()
873+
{
874+
__git_list_commands all
875+
}
876+
858877
__git_all_commands=
859878
__git_compute_all_commands ()
860879
{
@@ -864,89 +883,7 @@ __git_compute_all_commands ()
864883

865884
__git_list_porcelain_commands ()
866885
{
867-
local i IFS=" "$'\n'
868-
__git_compute_all_commands
869-
for i in $__git_all_commands
870-
do
871-
case $i in
872-
*--*) : helper pattern;;
873-
applymbox) : ask gittus;;
874-
applypatch) : ask gittus;;
875-
archimport) : import;;
876-
cat-file) : plumbing;;
877-
check-attr) : plumbing;;
878-
check-ignore) : plumbing;;
879-
check-mailmap) : plumbing;;
880-
check-ref-format) : plumbing;;
881-
checkout-index) : plumbing;;
882-
column) : internal helper;;
883-
commit-tree) : plumbing;;
884-
count-objects) : infrequent;;
885-
credential) : credentials;;
886-
credential-*) : credentials helper;;
887-
cvsexportcommit) : export;;
888-
cvsimport) : import;;
889-
cvsserver) : daemon;;
890-
daemon) : daemon;;
891-
diff-files) : plumbing;;
892-
diff-index) : plumbing;;
893-
diff-tree) : plumbing;;
894-
fast-import) : import;;
895-
fast-export) : export;;
896-
fsck-objects) : plumbing;;
897-
fetch-pack) : plumbing;;
898-
fmt-merge-msg) : plumbing;;
899-
for-each-ref) : plumbing;;
900-
hash-object) : plumbing;;
901-
http-*) : transport;;
902-
index-pack) : plumbing;;
903-
init-db) : deprecated;;
904-
local-fetch) : plumbing;;
905-
ls-files) : plumbing;;
906-
ls-remote) : plumbing;;
907-
ls-tree) : plumbing;;
908-
mailinfo) : plumbing;;
909-
mailsplit) : plumbing;;
910-
merge-*) : plumbing;;
911-
mktree) : plumbing;;
912-
mktag) : plumbing;;
913-
pack-objects) : plumbing;;
914-
pack-redundant) : plumbing;;
915-
pack-refs) : plumbing;;
916-
parse-remote) : plumbing;;
917-
patch-id) : plumbing;;
918-
prune) : plumbing;;
919-
prune-packed) : plumbing;;
920-
quiltimport) : import;;
921-
read-tree) : plumbing;;
922-
receive-pack) : plumbing;;
923-
remote-*) : transport;;
924-
rerere) : plumbing;;
925-
rev-list) : plumbing;;
926-
rev-parse) : plumbing;;
927-
runstatus) : plumbing;;
928-
sh-setup) : internal;;
929-
shell) : daemon;;
930-
show-ref) : plumbing;;
931-
send-pack) : plumbing;;
932-
show-index) : plumbing;;
933-
ssh-*) : transport;;
934-
stripspace) : plumbing;;
935-
symbolic-ref) : plumbing;;
936-
unpack-file) : plumbing;;
937-
unpack-objects) : plumbing;;
938-
update-index) : plumbing;;
939-
update-ref) : plumbing;;
940-
update-server-info) : daemon;;
941-
upload-archive) : plumbing;;
942-
upload-pack) : plumbing;;
943-
write-tree) : plumbing;;
944-
var) : infrequent;;
945-
verify-pack) : infrequent;;
946-
verify-tag) : plumbing;;
947-
*) echo $i;;
948-
esac
949-
done
886+
__git_list_commands porcelain
950887
}
951888

952889
__git_porcelain_commands=

t/t9902-completion.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ complete ()
1313
return 0
1414
}
1515

16-
# Be careful when updating this list:
16+
# Be careful when updating these lists:
1717
#
1818
# (1) The build tree may have build artifact from different branch, or
1919
# the user's $PATH may have a random executable that may begin
@@ -30,7 +30,8 @@ complete ()
3030
# completion for "git <TAB>", and a plumbing is excluded. "add",
3131
# "filter-branch" and "ls-files" are listed for this.
3232

33-
GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'
33+
GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr filter-branch ls-files'
34+
GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout filter-branch'
3435

3536
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
3637

0 commit comments

Comments
 (0)