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>

Nguyễn Thái Ngọc Duy committed May 20, 2018 at 20:40 UTC 84a971310656b7f553b48ca30bcd8936c95b00c9
3 files changed +58 -119
command-list.txt
+27 -26
@@ -47,12 +47,12 @@
47 # command name category [category] [category]
48 git-add mainporcelain worktree
49 git-am mainporcelain
50 -git-annotate ancillaryinterrogators
51 -git-apply plumbingmanipulators
50 +git-annotate ancillaryinterrogators complete
51 +git-apply plumbingmanipulators complete
52 git-archimport foreignscminterface
53 git-archive mainporcelain
54 git-bisect mainporcelain info
55 -git-blame ancillaryinterrogators
55 +git-blame ancillaryinterrogators complete
56 git-branch mainporcelain history
57 git-bundle mainporcelain
58 git-cat-file plumbinginterrogators
@@ -62,7 +62,7 @@ git-check-mailmap purehelpers
62 git-checkout mainporcelain history
63 git-checkout-index plumbingmanipulators
64 git-check-ref-format purehelpers
65 -git-cherry ancillaryinterrogators
65 +git-cherry ancillaryinterrogators complete
66 git-cherry-pick mainporcelain
67 git-citool mainporcelain
68 git-clean mainporcelain
@@ -70,7 +70,7 @@ git-clone mainporcelain init
70 git-column purehelpers
71 git-commit mainporcelain history
72 git-commit-tree plumbingmanipulators
73 -git-config ancillarymanipulators
73 +git-config ancillarymanipulators complete
74 git-count-objects ancillaryinterrogators
75 git-credential purehelpers
76 git-credential-cache purehelpers
@@ -84,30 +84,30 @@ git-diff mainporcelain history
84 git-diff-files plumbinginterrogators
85 git-diff-index plumbinginterrogators
86 git-diff-tree plumbinginterrogators
87 -git-difftool ancillaryinterrogators
87 +git-difftool ancillaryinterrogators complete
88 git-fast-export ancillarymanipulators
89 git-fast-import ancillarymanipulators
90 git-fetch mainporcelain remote
91 git-fetch-pack synchingrepositories
92 -git-filter-branch ancillarymanipulators
92 +git-filter-branch ancillarymanipulators complete
93 git-fmt-merge-msg purehelpers
94 git-for-each-ref plumbinginterrogators
95 git-format-patch mainporcelain
96 -git-fsck ancillaryinterrogators
96 +git-fsck ancillaryinterrogators complete
97 git-gc mainporcelain
98 -git-get-tar-commit-id ancillaryinterrogators
98 +git-get-tar-commit-id ancillaryinterrogators complete
99 git-grep mainporcelain info
100 git-gui mainporcelain
101 git-hash-object plumbingmanipulators
102 -git-help ancillaryinterrogators
102 +git-help ancillaryinterrogators complete
103 git-http-backend synchingrepositories
104 git-http-fetch synchelpers
105 git-http-push synchelpers
106 -git-imap-send foreignscminterface
106 +git-imap-send foreignscminterface complete
107 git-index-pack plumbingmanipulators
108 git-init mainporcelain init
109 -git-instaweb ancillaryinterrogators
110 -git-interpret-trailers purehelpers
109 +git-instaweb ancillaryinterrogators complete
110 +git-interpret-trailers purehelpers complete
111 gitk mainporcelain
112 git-log mainporcelain info
113 git-ls-files plumbinginterrogators
@@ -120,14 +120,14 @@ git-merge-base plumbinginterrogators
120 git-merge-file plumbingmanipulators
121 git-merge-index plumbingmanipulators
122 git-merge-one-file purehelpers
123 -git-mergetool ancillarymanipulators
123 +git-mergetool ancillarymanipulators complete
124 git-merge-tree ancillaryinterrogators
125 git-mktag plumbingmanipulators
126 git-mktree plumbingmanipulators
127 git-mv mainporcelain worktree
128 -git-name-rev plumbinginterrogators
128 +git-name-rev plumbinginterrogators complete
129 git-notes mainporcelain
130 -git-p4 foreignscminterface
130 +git-p4 foreignscminterface complete
131 git-pack-objects plumbingmanipulators
132 git-pack-redundant plumbinginterrogators
133 git-pack-refs ancillarymanipulators
@@ -141,32 +141,33 @@ git-quiltimport foreignscminterface
141 git-read-tree plumbingmanipulators
142 git-rebase mainporcelain history
143 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
149 git-rerere ancillaryinterrogators
150 git-reset mainporcelain worktree
151 git-revert mainporcelain
152 git-rev-list plumbinginterrogators
153 git-rev-parse ancillaryinterrogators
154 git-rm mainporcelain worktree
155 -git-send-email foreignscminterface
155 +git-send-email foreignscminterface complete
156 git-send-pack synchingrepositories
157 git-shell synchelpers
158 git-shortlog mainporcelain
159 git-show mainporcelain info
160 -git-show-branch ancillaryinterrogators
160 +git-show-branch ancillaryinterrogators complete
161 git-show-index plumbinginterrogators
162 git-show-ref plumbinginterrogators
163 git-sh-i18n purehelpers
164 git-sh-setup purehelpers
165 git-stash mainporcelain
166 +git-stage complete
167 git-status mainporcelain info
168 git-stripspace purehelpers
169 git-submodule mainporcelain
169 -git-svn foreignscminterface
170 +git-svn foreignscminterface complete
171 git-symbolic-ref plumbingmanipulators
172 git-tag mainporcelain history
173 git-unpack-file plumbinginterrogators
@@ -177,11 +178,11 @@ git-update-server-info synchingrepositories
178 git-upload-archive synchelpers
179 git-upload-pack synchelpers
180 git-var plumbinginterrogators
180 -git-verify-commit ancillaryinterrogators
181 +git-verify-commit ancillaryinterrogators complete
182 git-verify-pack plumbinginterrogators
183 git-verify-tag ancillaryinterrogators
184 gitweb ancillaryinterrogators
184 -git-whatchanged ancillaryinterrogators
185 +git-whatchanged ancillaryinterrogators complete
186 git-worktree mainporcelain
187 git-write-tree plumbingmanipulators
188 gitattributes guide
contrib/completion/git-completion.bash
+28 -91
@@ -834,19 +834,33 @@ __git_complete_strategy ()
834 return 1
835 }
836
837 +# __git_commands requires 1 argument:
838 +# 1: the command group, either "all" or "porcelain"
839 __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
858 }
859
846 -__git_list_all_commands ()
860 +__git_list_commands ()
861 {
862 local i IFS=" "$'\n'
849 - for i in $(__git_commands)
863 + for i in $(__git_commands $1)
864 do
865 case $i in
866 *--*) : helper pattern;;
@@ -855,6 +869,11 @@ __git_list_all_commands ()
869 done
870 }
871
872 +__git_list_all_commands ()
873 +{
874 + __git_list_commands all
875 +}
876 +
877 __git_all_commands=
878 __git_compute_all_commands ()
879 {
@@ -864,89 +883,7 @@ __git_compute_all_commands ()
883
884 __git_list_porcelain_commands ()
885 {
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
887 }
888
889 __git_porcelain_commands=
t/t9902-completion.sh
+3 -2
@@ -13,7 +13,7 @@ complete ()
13 return 0
14 }
15
16 -# Be careful when updating this list:
16 +# Be careful when updating these lists:
17 #
18 # (1) The build tree may have build artifact from different branch, or
19 # the user's $PATH may have a random executable that may begin
@@ -30,7 +30,8 @@ complete ()
30 # completion for "git <TAB>", and a plumbing is excluded. "add",
31 # "filter-branch" and "ls-files" are listed for this.
32
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'
35
36 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
37