{"thread":{"id":"57285","subject":"Some sub-commands can't be completed by TAB key.","startedAt":"2022-01-22T08:42:16Z","lastAt":"2022-02-07T07:06:57Z","messageCount":17,"participants":["Hongyi Zhao","Johannes Sixt","Philippe Blain","Junio C Hamano","João Victor Bonfim","Ævar Arnfjörð Bjarmason","SZEDER Gábor"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"446682","messageId":"CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com","threadId":"57285","inReplyTo":null,"subject":"Some sub-commands can't be completed by TAB key.","fromName":"Hongyi Zhao","fromEmail":"hongyi.zhao@gmail.com","sentAt":"2022-01-22T08:42:02Z","receivedAt":"2022-01-22T08:42:16Z","isPatch":false,"sender":{"key":"hongyi.zhao@gmail.com","avatar":null},"body":"On Ubuntu 20.04.3 LTS, I use the following git version installed from\nits apt repository:\n\n$ git --version\ngit version 2.25.1\n\nI find that there are some  sub-commands can't be completed by TAB key:\n\n$ git <TAB>\nadd               cherry-pick       fetch             latexdiff\n pull              restore           status\nam                citool            format-patch      log\n push              revert            submodule\napply             clean             fsck              merge\n range-diff        rm                switch\narchive           clone             gc                mergetool\n rebase            send-email        tag\nbisect            commit            gitk              mv\n reflog            shortlog          whatchanged\nblame             config            grep              nbdiffdriver\n remote            show              worktree\nbranch            deborig           gui               nbdifftool\n repack            show-branch\nbundle            describe          help              nbmergedriver\n replace           sparse-checkout\ncheckout          diff              init              nbmergetool\n request-pull      stage\ncherry            difftool          instaweb          notes\n reset             stash\n\nAs you can see, there are some sub-commands which are not listed in\nthe above list, for example, the following ones:\n\n$ git ls-remote\n$ git ls-files\n\nAny hints for this problem?\n\nRegards\n-- \nAssoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>\nTheory and Simulation of Materials\nHebei Vocational University of Technology and Engineering\nNo. 473, Quannan West Street, Xindu District, Xingtai, Hebei province\n"},{"id":"446692","messageId":"5373af01-eeae-fb66-e9f7-41f2a022b275@kdbg.org","threadId":"57285","inReplyTo":"CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-01-22T14:47:45Z","receivedAt":"2022-01-22T14:47:49Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 22.01.22 um 09:42 schrieb Hongyi Zhao:\n> I find that there are some  sub-commands can't be completed by TAB key:\n> \n> $ git <TAB>\n> add               cherry-pick       fetch             latexdiff\n> [...]\n> As you can see, there are some sub-commands which are not listed in\n> the above list, for example, the following ones:\n> \n> $ git ls-remote\n> $ git ls-files\n> \n> Any hints for this problem?\n\nTab completion is only available for user-facing sub-commands\n(\"porcelain\"), but not for sub-commands intended for scripting\n(\"plumbing\"). The intent is to make tab completion more efficient during\nday-to-day work on the command line. For example,\n\n   $ git l<TAB>\n\narrives at\n\n   $ git log <cursor here>\n\ninstead of\n\n   log     ls-files     ls-remote     ls-tree\n   $ git l<cursor here>\n\n-- Hannes\n"},{"id":"446713","messageId":"CAGP6PO+GMi6jqRZ5HWxES5GDYkEDHoXOOZ+VvDkm0sC4nxkT4Q@mail.gmail.com","threadId":"57285","inReplyTo":"5373af01-eeae-fb66-e9f7-41f2a022b275@kdbg.org","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Hongyi Zhao","fromEmail":"hongyi.zhao@gmail.com","sentAt":"2022-01-23T00:38:17Z","receivedAt":"2022-01-23T00:38:32Z","isPatch":false,"sender":{"key":"hongyi.zhao@gmail.com","avatar":null},"body":"On Sat, Jan 22, 2022 at 10:47 PM Johannes Sixt <j6t@kdbg.org> wrote:\n>\n> Am 22.01.22 um 09:42 schrieb Hongyi Zhao:\n> > I find that there are some  sub-commands can't be completed by TAB key:\n> >\n> > $ git <TAB>\n> > add               cherry-pick       fetch             latexdiff\n> > [...]\n> > As you can see, there are some sub-commands which are not listed in\n> > the above list, for example, the following ones:\n> >\n> > $ git ls-remote\n> > $ git ls-files\n> >\n> > Any hints for this problem?\n>\n> Tab completion is only available for user-facing sub-commands\n> (\"porcelain\"), but not for sub-commands intended for scripting\n> (\"plumbing\"). The intent is to make tab completion more efficient during\n> day-to-day work on the command line. For example,\n\nBut there are so many git sub-commands, so if the plumbing feature is\nsupported, it will facilitate user to check the availability of some\nsub-commands.\n\n>    $ git l<TAB>\n>\n> arrives at\n>\n>    $ git log <cursor here>\n\nI see the following:\n\n$ git l<TAB>\nlatexdiff   log\n\n> instead of\n>\n>    log     ls-files     ls-remote     ls-tree\n>    $ git l<cursor here>\n>\n> -- Hannes\n"},{"id":"446720","messageId":"5a30ac1f-d414-0976-cd08-7b059117af41@gmail.com","threadId":"57285","inReplyTo":"CAGP6PO+GMi6jqRZ5HWxES5GDYkEDHoXOOZ+VvDkm0sC4nxkT4Q@mail.gmail.com","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-01-23T17:31:18Z","receivedAt":"2022-01-23T17:31:23Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Hongyi,\n\nLe 2022-01-22 à 19:38, Hongyi Zhao a écrit :\n> On Sat, Jan 22, 2022 at 10:47 PM Johannes Sixt <j6t@kdbg.org> wrote:\n>>\n>> Am 22.01.22 um 09:42 schrieb Hongyi Zhao:\n>>> I find that there are some  sub-commands can't be completed by TAB key:\n>>>\n>>> $ git <TAB>\n>>> add               cherry-pick       fetch             latexdiff\n>>> [...]\n>>> As you can see, there are some sub-commands which are not listed in\n>>> the above list, for example, the following ones:\n>>>\n>>> $ git ls-remote\n>>> $ git ls-files\n>>>\n>>> Any hints for this problem?\n>>\n>> Tab completion is only available for user-facing sub-commands\n>> (\"porcelain\"), but not for sub-commands intended for scripting\n>> (\"plumbing\"). The intent is to make tab completion more efficient during\n>> day-to-day work on the command line. For example,\n> \n> But there are so many git sub-commands, so if the plumbing feature is\n> supported, it will facilitate user to check the availability of some\n> sub-commands.\n\nIf what you want to do is \"check the availability\" of some sub-command,\nyou can simply do 'git <subcommand> -h', for example, and see if Git recognizes\nthe subcommand. \n\nIf you mean discovering Git commands, you can use 'git help -a', which will list\nall commands, including pluming commands.\n\nIf you want to customize the Bash completion so that some select plumbing \ncommands do appear in the tab completion, you can use the config \n'completion.commands' [1]. Setting it to \"ls-files ls-remote ls-tree\"\nwould then give you your desired output below.\n\n> \n>>    $ git l<TAB>\n>>\n>> arrives at\n>>\n>>    $ git log <cursor here>\n> \n> I see the following:\n> \n> $ git l<TAB>\n> latexdiff   log\n\nThis would mean you have a 'git-latexdiff' command somewhere in your PATH.\n\nHope that helps,\n\nPhilippe.\n\n[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-completioncommands\n"},{"id":"446722","messageId":"xmqqpmoi9qna.fsf@gitster.g","threadId":"57285","inReplyTo":"5a30ac1f-d414-0976-cd08-7b059117af41@gmail.com","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-01-23T19:51:53Z","receivedAt":"2022-01-23T19:51:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n>> I see the following:\n>> \n>> $ git l<TAB>\n>> latexdiff   log\n>\n> This would mean you have a 'git-latexdiff' command somewhere in your PATH.\n\nTrue.  On Debian-based systems, the texlive-extra-utils package has\n/usr/bin/git-latexdiff and that is likely where it came from.\n\nIt is also worth noting that completion will also include whatever\nalias.  I get \"lg\" in the mix because I have\n\n        [alias]\n                lg = \"log --oneline\"\n\nin my $HOME/.gitconfig, for example.\n"},{"id":"446732","messageId":"CAGP6POK22pCY+_bMCnwRx3h0kE9GpZoq1Pk2hJZoyE_O06WnDw@mail.gmail.com","threadId":"57285","inReplyTo":"xmqqpmoi9qna.fsf@gitster.g","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Hongyi Zhao","fromEmail":"hongyi.zhao@gmail.com","sentAt":"2022-01-24T01:42:35Z","receivedAt":"2022-01-24T01:48:19Z","isPatch":false,"sender":{"key":"hongyi.zhao@gmail.com","avatar":null},"body":"On Mon, Jan 24, 2022 at 3:51 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Philippe Blain <levraiphilippeblain@gmail.com> writes:\n>\n> >> I see the following:\n> >>\n> >> $ git l<TAB>\n> >> latexdiff   log\n> >\n> > This would mean you have a 'git-latexdiff' command somewhere in your PATH.\n>\n> True.  On Debian-based systems, the texlive-extra-utils package has\n> /usr/bin/git-latexdiff and that is likely where it came from.\n\nMine comes from TexLive:\n\n$ which git-latexdiff\n/opt/texlive/2021/bin/x86_64-linux/git-latexdiff\n\n\n> It is also worth noting that completion will also include whatever\n> alias.  I get \"lg\" in the mix because I have\n>\n>         [alias]\n>                 lg = \"log --oneline\"\n>\n> in my $HOME/.gitconfig, for example.\n\nGood example. Got it.\n\nHZ\n"},{"id":"446737","messageId":"Odvn8_XIojrgpHG7xMtrBXdhoxr20X_fFRYoDtvkUKb1FOd-13j_l40TBAc1hn7rSddJ-YrQak8AuetNQ9LkeVeVoS3RTlIeSQ9znqyMApc=@protonmail.com","threadId":"57285","inReplyTo":"xmqqpmoi9qna.fsf@gitster.g","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"João Victor Bonfim","fromEmail":"joaovictorbonfim+git-mail-list@protonmail.com","sentAt":"2022-01-24T09:18:42Z","receivedAt":"2022-01-24T09:18:47Z","isPatch":false,"sender":{"key":"joaovictorbonfim+git-mail-list@protonmail.com","avatar":null},"body":"> It is also worth noting that completion will also include whatever\n> alias.  I get \"lg\" in the mix because I have...\n\nThat sounds like something that should be hidden, no?\nLike, all aliases are left unmentioned?\n"},{"id":"446832","messageId":"xmqq1r0w1d8a.fsf@gitster.g","threadId":"57285","inReplyTo":"Odvn8_XIojrgpHG7xMtrBXdhoxr20X_fFRYoDtvkUKb1FOd-13j_l40TBAc1hn7rSddJ-YrQak8AuetNQ9LkeVeVoS3RTlIeSQ9znqyMApc=@protonmail.com","subject":"Re: Some sub-commands can't be completed by TAB key.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-01-25T07:33:25Z","receivedAt":"2022-01-25T07:36:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"João Victor Bonfim  <JoaoVictorBonfim+Git-Mail-List@protonmail.com>\nwrites:\n\n>> It is also worth noting that completion will also include whatever\n>> alias.  I get \"lg\" in the mix because I have...\n>\n> That sounds like something that should be hidden, no?\n> Like, all aliases are left unmentioned?\n\nUnlike the plumbing commands that are meant to be used in writing\nscripts and not typed in interactive sessions, and more like\nPorcelain commands that are meant to be used by human end-users in\ntheir interactive sessions by getting typed from the keyboard, an\naliase is often (and certainly my \"lg\" is) defined in order to give\na short-and-sweet typesaver to a command with common initial options\nthat the user finds useful in their interactive sessions.\n\nI am curious to find out what makes you think it is a good idea to\nomit them from completion.\n\n\n"},{"id":"446844","messageId":"patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com","threadId":"57285","inReplyTo":"CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com","subject":"[PATCH] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-01-25T12:49:04Z","receivedAt":"2022-01-25T12:51:20Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go\nwith the existing GIT_COMPLETION_SHOW_ALL=1 added in\nc099f579b98 (completion: add GIT_COMPLETION_SHOW_ALL env var,\n2020-08-19).\n\nThis will include plumbing commands such as \"cat-file\" in \"git <TAB>\"\nand \"git c<TAB>\" completion. Without/with this I have 134 and 243\ncompletion with git <TAB>, respectively.\n\nIt was already possible to do this by tweaking\nGIT_COMPLETION_SHOW_ALL_COMMANDS from the outside, that testing\nvariable was added in 84a97131065 (completion: let git provide the\ncompletable command list, 2018-05-20). Doing this before loading\ngit-completion.bash worked:\n\n    export GIT_TESTING_PORCELAIN_COMMAND_LIST=\"$(git --list-cmds=builtins,main,list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n\nBut such testing variables are not meant to be used from the outside,\nand we make no guarantees that those internal won't change. So let's\nexpose this as a dedicated configuration knob.\n\n1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/\n\nReported-by: Hongyi Zhao <hongyi.zhao@gmail.com>\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nn Sat, Jan 22 2022, Hongyi Zhao wrote:\n\n> On Ubuntu 20.04.3 LTS, I use the following git version installed from\n> its apt repository:\n>\n> $ git --version\n> git version 2.25.1\n>\n> I find that there are some  sub-commands can't be completed by TAB key\n> [...]\n\nOthers have explained why this happens, but as noted above an easy but\nundocumented workaround for this that I use, because I'd like\ne.g. \"cat-file\" to show up in this completion. In your ~/.bashrc or\nequivalent do something like this before it loads git-completion.bash:\n\n    export GIT_TESTING_PORCELAIN_COMMAND_LIST=\"$(git --list-cmds=builtins,main,others,alias)\"\n\nBut it would be even nicer to turn that into a first-class feature,\nthis patch does so. With this you can just do:\n\n    export GIT_COMPLETION_SHOW_ALL_COMMANDS=1\n\n contrib/completion/git-completion.bash | 13 ++++++++++++-\n t/t9902-completion.sh                  | 27 ++++++++++++++++++++++++++\n 2 files changed, 39 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 377d6c5494a..2436b8eb6b9 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -49,6 +49,11 @@\n #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n #     exists).\n #\n+#   GIT_COMPLETION_SHOW_ALL_COMMANDS\n+#\n+#     When set to \"1\" suggest all commands, including plumbing commands\n+#     which are hidden by default (e.g. \"cat-file\" on \"git ca<TAB>\").\n+#\n #   GIT_COMPLETION_SHOW_ALL\n #\n #     When set to \"1\" suggest all options, including options which are\n@@ -3455,7 +3460,13 @@ __git_main ()\n \t\t\tthen\n \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n \t\t\telse\n-\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\tlocal list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config\n+\n+\t\t\t\tif test \"${GIT_COMPLETION_SHOW_ALL_COMMANDS-}\" = \"1\"\n+\t\t\t\tthen\n+\t\t\t\t\tlist_cmds=builtins,$list_cmds\n+\t\t\t\tfi\n+\t\t\t\t__gitcomp \"$(__git --list-cmds=$list_cmds)\"\n \t\t\tfi\n \t\t\t;;\n \t\tesac\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 98c62806328..e3ea6a41b00 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2432,6 +2432,33 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \tEOF\n '\n \n+test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n+\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n+\n+\t# Just mainporcelain, not plumbing commands\n+\trun_completion \"git c\" &&\n+\tgrep checkout out &&\n+\t! grep cat-file out\n+'\n+\n+test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n+\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n+\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n+\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n+\n+\t# Both mainporcelain and plumbing commands\n+\trun_completion \"git c\" &&\n+\tgrep checkout out &&\n+\tgrep cat-file out &&\n+\n+\t# Check \"gitk\", a \"main\" command, but not a built-in + more plumbing\n+\trun_completion \"git g\" &&\n+\tgrep gitk out &&\n+\tgrep get-tar-commit-id out\n+'\n+\n test_expect_success '__git_complete' '\n \tunset -f __git_wrap__git_main &&\n \n-- \n2.35.0.rc2.886.ga87834885e8\n\n"},{"id":"447010","messageId":"xmqqk0emp1m8.fsf@gitster.g","threadId":"57285","inReplyTo":"patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com","subject":"Re: [PATCH] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-01-26T22:34:55Z","receivedAt":"2022-01-26T22:35:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go\n> with the existing GIT_COMPLETION_SHOW_ALL=1 added in\n> c099f579b98 (completion: add GIT_COMPLETION_SHOW_ALL env var,\n> 2020-08-19).\n>\n> This will include plumbing commands such as \"cat-file\" in \"git <TAB>\"\n> and \"git c<TAB>\" completion. Without/with this I have 134 and 243\n> completion with git <TAB>, respectively.\n\nOK.  This makes sense in the sense that more choice is better.\n\n> It was already possible to do this by tweaking\n> GIT_COMPLETION_SHOW_ALL_COMMANDS from the outside, that testing\n> variable was added in 84a97131065 (completion: let git provide the\n> completable command list, 2018-05-20). Doing this before loading\n> git-completion.bash worked:\n\nPerhaps there is a typo that ruined whole the paragraph.  We are\nadding that variable with this patch, so by definition, it did not\nexist before, which means we cannot \"tweak\" it because it did not\nexist.\n\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -49,6 +49,11 @@\n>  #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n>  #     exists).\n>  #\n> +#   GIT_COMPLETION_SHOW_ALL_COMMANDS\n> +#\n> +#     When set to \"1\" suggest all commands, including plumbing commands\n> +#     which are hidden by default (e.g. \"cat-file\" on \"git ca<TAB>\").\n> +#\n\nUsually we frown upon inserting a new thing to the middle of a list\nof things that has no inherent order.  In this case, I think this is\nOK, as the existing \"all\" (below) is about completing options, while\nthe new one is about completing subcommands, and the latter is at a\nhigher conceptual level than the former.\n\n>  #   GIT_COMPLETION_SHOW_ALL\n>  #\n>  #     When set to \"1\" suggest all options, including options which are\n> @@ -3455,7 +3460,13 @@ __git_main ()\n>  \t\t\tthen\n>  \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n>  \t\t\telse\n> -\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n> +\t\t\t\tlocal list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config\n> +\n> +\t\t\t\tif test \"${GIT_COMPLETION_SHOW_ALL_COMMANDS-}\" = \"1\"\n> +\t\t\t\tthen\n> +\t\t\t\t\tlist_cmds=builtins,$list_cmds\n\nIt is sad that there is no \"plumbing\" class (assuming the goal is\n\"we by default exclude plumbing, so add that to the list\"), or just\n\"everything under the sun\" class.  If there were a plumbing command\nthat is not implemented as a built-in, adding buitlins to list_cmds\nwill not show the command, will it?  Also, because nohelpers is not\nremoved from list_cmds, whatever command that were removed from\nexclude_helpers_from_list() will be hidden.\n\nIt looks as though help.c needs a new list_all_cmds() that can be\ncalled from git.c::list_cmds() when \"all\" is asked for, and dumps\neverything from command_list[] plus whatever load_command_list()\nloads.\n\n> +\t\t\t\tfi\n> +\t\t\t\t__gitcomp \"$(__git --list-cmds=$list_cmds)\"\n>  \t\t\tfi\n>  \t\t\t;;\n>  \t\tesac\n\nHaving said all that, assuming that including \"builtins\" is a good\nenough approximation (which I do not have no opinion on), the\nimplementation looks good to me.\n\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index 98c62806328..e3ea6a41b00 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -2432,6 +2432,33 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n>  \tEOF\n>  '\n>  \n> +test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n> +\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n> +\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n\nAs we've done dot-sourcing of the file at the beginning of the\nscript already, dot-sourcing the same thing again would only\noverwrite what was done before, without clearing the deck.  Which\nmay not hurt for the purpose of _this_ test _right_ _now_q.\n\nBut as this is not done inside a subshell, whetever we dot-source\nhere will persist til the end of the script.  Which may be more\nproblematic as it will affect the tests that come (and new tests\nthat will be added) after this point.\n\nThe same comment applies to the other new test added immediately\nafter this one.\n\nOther than that, looks sensible to me.\n\nThanks.\n"},{"id":"447529","messageId":"cover-v2-0.2-00000000000-20220202T111228Z-avarab@gmail.com","threadId":"57285","inReplyTo":"patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com","subject":"[PATCH v2 0/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-02-02T11:15:08Z","receivedAt":"2022-02-02T11:15:19Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This series adds an opt-in configuration to make \"git <TAB>\" complete\nthe likes of \"cat-file\" (plumbing), in addition to the existing\ncompletion for the likes of \"status\" (porcelain).\n\nThis v2 addresses feedback from Junio on the v1, I also added a\npreceding patch to change the re-sourcing of git-completion.bash in\nsome existing tests to use a subshell, which is a pattern I'd buggily\ncopied in the v1.\n\nÆvar Arnfjörð Bjarmason (2):\n  completion tests: re-source git-completion.bash in a subshell\n  completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS\n\n contrib/completion/git-completion.bash | 13 ++++-\n t/t9902-completion.sh                  | 81 +++++++++++++++++++-------\n 2 files changed, 72 insertions(+), 22 deletions(-)\n\nRange-diff against v1:\n-:  ----------- > 1:  cf09546e079 completion tests: re-source git-completion.bash in a subshell\n1:  5f18305ca08 ! 2:  2e2e3569e02 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS\n    @@ Commit message\n         completion with git <TAB>, respectively.\n     \n         It was already possible to do this by tweaking\n    -    GIT_COMPLETION_SHOW_ALL_COMMANDS from the outside, that testing\n    +    GIT_TESTING_PORCELAIN_COMMAND_LIST= from the outside, that testing\n         variable was added in 84a97131065 (completion: let git provide the\n         completable command list, 2018-05-20). Doing this before loading\n         git-completion.bash worked:\n    @@ Commit message\n         and we make no guarantees that those internal won't change. So let's\n         expose this as a dedicated configuration knob.\n     \n    +    It would be better to teach --list-cmds=* a new category which would\n    +    include all of these groups, but that's a larger change that we can\n    +    leave for some other time.\n    +\n         1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/\n     \n         Reported-by: Hongyi Zhao <hongyi.zhao@gmail.com>\n    @@ contrib/completion/git-completion.bash: __git_main ()\n     \n      ## t/t9902-completion.sh ##\n     @@ t/t9902-completion.sh: test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n    - \tEOF\n    + \t)\n      '\n      \n     +test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n    -+\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n    -+\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n    ++\t(\n    ++\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n    ++\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n     +\n    -+\t# Just mainporcelain, not plumbing commands\n    -+\trun_completion \"git c\" &&\n    -+\tgrep checkout out &&\n    -+\t! grep cat-file out\n    ++\t\t# Just mainporcelain, not plumbing commands\n    ++\t\trun_completion \"git c\" &&\n    ++\t\tgrep checkout out &&\n    ++\t\t! grep cat-file out\n    ++\t)\n     +'\n     +\n     +test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n    -+\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n    -+\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n    -+\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n    -+\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n    ++\t(\n    ++\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n    ++\t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n    ++\t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n    ++\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n     +\n    -+\t# Both mainporcelain and plumbing commands\n    -+\trun_completion \"git c\" &&\n    -+\tgrep checkout out &&\n    -+\tgrep cat-file out &&\n    ++\t\t# Both mainporcelain and plumbing commands\n    ++\t\trun_completion \"git c\" &&\n    ++\t\tgrep checkout out &&\n    ++\t\tgrep cat-file out &&\n     +\n    -+\t# Check \"gitk\", a \"main\" command, but not a built-in + more plumbing\n    -+\trun_completion \"git g\" &&\n    -+\tgrep gitk out &&\n    -+\tgrep get-tar-commit-id out\n    ++\t\t# Check \"gitk\", a \"main\" command, but not a built-in + more plumbing\n    ++\t\trun_completion \"git g\" &&\n    ++\t\tgrep gitk out &&\n    ++\t\tgrep get-tar-commit-id out\n    ++\t)\n     +'\n     +\n      test_expect_success '__git_complete' '\n-- \n2.35.0.913.g12b4baa2536\n\n"},{"id":"447530","messageId":"patch-v2-1.2-cf09546e079-20220202T111228Z-avarab@gmail.com","threadId":"57285","inReplyTo":"cover-v2-0.2-00000000000-20220202T111228Z-avarab@gmail.com","subject":"[PATCH v2 1/2] completion tests: re-source git-completion.bash in a subshell","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-02-02T11:15:09Z","receivedAt":"2022-02-02T11:15:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change tests of git-completion.bash that re-source it to do so inside\na subshell. Re-sourcing it will clobber variables it sets, and in the\ncase of the \"GIT_COMPLETION_SHOW_ALL=1\" test added in\nca2d62b7879 (parse-options: don't complete option aliases by default,\n2021-07-16) change the behavior of the completion persistently.\n\nAside from the addition of \"(\" and \")\" on new lines this is an\nindentation-only change, only the \"(\" and \")\" lines are changed under\n\"git diff -w\".\n\nSo let's change that test, and for good measure do the same for the\nthree tests that precede it, which were added in\n8b0eaa41f23 (completion: clear cached --options when sourcing the\ncompletion script, 2018-03-22). The may not be wrong, but doing this\nestablishes a more reliable pattern for future tests, which might use\nthese as a template to copy.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/t9902-completion.sh | 50 +++++++++++++++++++++++++------------------\n 1 file changed, 29 insertions(+), 21 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 98c62806328..c9805f2147d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2396,27 +2396,33 @@ test_expect_success 'options with value' '\n '\n \n test_expect_success 'sourcing the completion script clears cached commands' '\n-\t__git_compute_all_commands &&\n-\tverbose test -n \"$__git_all_commands\" &&\n-\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n-\tverbose test -z \"$__git_all_commands\"\n+\t(\n+\t\t__git_compute_all_commands &&\n+\t\tverbose test -n \"$__git_all_commands\" &&\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tverbose test -z \"$__git_all_commands\"\n+\t)\n '\n \n test_expect_success 'sourcing the completion script clears cached merge strategies' '\n-\t__git_compute_merge_strategies &&\n-\tverbose test -n \"$__git_merge_strategies\" &&\n-\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n-\tverbose test -z \"$__git_merge_strategies\"\n+\t(\n+\t\t__git_compute_merge_strategies &&\n+\t\tverbose test -n \"$__git_merge_strategies\" &&\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tverbose test -z \"$__git_merge_strategies\"\n+\t)\n '\n \n test_expect_success 'sourcing the completion script clears cached --options' '\n-\t__gitcomp_builtin checkout &&\n-\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n-\t__gitcomp_builtin notes_edit &&\n-\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n-\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n-\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n+\t(\n+\t\t__gitcomp_builtin checkout &&\n+\t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n+\t\t__gitcomp_builtin notes_edit &&\n+\t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n+\t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n+\t)\n '\n \n test_expect_success 'option aliases are not shown by default' '\n@@ -2424,12 +2430,14 @@ test_expect_success 'option aliases are not shown by default' '\n '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n-\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n-\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n-\ttest_completion \"git clone --recurs\" <<-\\EOF\n-\t--recurse-submodules Z\n-\t--recursive Z\n-\tEOF\n+\t(\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n+\t\ttest_completion \"git clone --recurs\" <<-\\EOF\n+\t\t--recurse-submodules Z\n+\t\t--recursive Z\n+\t\tEOF\n+\t)\n '\n \n test_expect_success '__git_complete' '\n-- \n2.35.0.913.g12b4baa2536\n\n"},{"id":"447531","messageId":"patch-v2-2.2-2e2e3569e02-20220202T111228Z-avarab@gmail.com","threadId":"57285","inReplyTo":"cover-v2-0.2-00000000000-20220202T111228Z-avarab@gmail.com","subject":"[PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-02-02T11:15:10Z","receivedAt":"2022-02-02T11:15:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go\nwith the existing GIT_COMPLETION_SHOW_ALL=1 added in\nc099f579b98 (completion: add GIT_COMPLETION_SHOW_ALL env var,\n2020-08-19).\n\nThis will include plumbing commands such as \"cat-file\" in \"git <TAB>\"\nand \"git c<TAB>\" completion. Without/with this I have 134 and 243\ncompletion with git <TAB>, respectively.\n\nIt was already possible to do this by tweaking\nGIT_TESTING_PORCELAIN_COMMAND_LIST= from the outside, that testing\nvariable was added in 84a97131065 (completion: let git provide the\ncompletable command list, 2018-05-20). Doing this before loading\ngit-completion.bash worked:\n\n    export GIT_TESTING_PORCELAIN_COMMAND_LIST=\"$(git --list-cmds=builtins,main,list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n\nBut such testing variables are not meant to be used from the outside,\nand we make no guarantees that those internal won't change. So let's\nexpose this as a dedicated configuration knob.\n\nIt would be better to teach --list-cmds=* a new category which would\ninclude all of these groups, but that's a larger change that we can\nleave for some other time.\n\n1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/\n\nReported-by: Hongyi Zhao <hongyi.zhao@gmail.com>\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/completion/git-completion.bash | 13 ++++++++++-\n t/t9902-completion.sh                  | 31 ++++++++++++++++++++++++++\n 2 files changed, 43 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 377d6c5494a..2436b8eb6b9 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -49,6 +49,11 @@\n #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n #     exists).\n #\n+#   GIT_COMPLETION_SHOW_ALL_COMMANDS\n+#\n+#     When set to \"1\" suggest all commands, including plumbing commands\n+#     which are hidden by default (e.g. \"cat-file\" on \"git ca<TAB>\").\n+#\n #   GIT_COMPLETION_SHOW_ALL\n #\n #     When set to \"1\" suggest all options, including options which are\n@@ -3455,7 +3460,13 @@ __git_main ()\n \t\t\tthen\n \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n \t\t\telse\n-\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\tlocal list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config\n+\n+\t\t\t\tif test \"${GIT_COMPLETION_SHOW_ALL_COMMANDS-}\" = \"1\"\n+\t\t\t\tthen\n+\t\t\t\t\tlist_cmds=builtins,$list_cmds\n+\t\t\t\tfi\n+\t\t\t\t__gitcomp \"$(__git --list-cmds=$list_cmds)\"\n \t\t\tfi\n \t\t\t;;\n \t\tesac\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex c9805f2147d..c6d6d6ef896 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2440,6 +2440,37 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t)\n '\n \n+test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n+\t(\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n+\n+\t\t# Just mainporcelain, not plumbing commands\n+\t\trun_completion \"git c\" &&\n+\t\tgrep checkout out &&\n+\t\t! grep cat-file out\n+\t)\n+'\n+\n+test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n+\t(\n+\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n+\t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n+\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n+\n+\t\t# Both mainporcelain and plumbing commands\n+\t\trun_completion \"git c\" &&\n+\t\tgrep checkout out &&\n+\t\tgrep cat-file out &&\n+\n+\t\t# Check \"gitk\", a \"main\" command, but not a built-in + more plumbing\n+\t\trun_completion \"git g\" &&\n+\t\tgrep gitk out &&\n+\t\tgrep get-tar-commit-id out\n+\t)\n+'\n+\n test_expect_success '__git_complete' '\n \tunset -f __git_wrap__git_main &&\n \n-- \n2.35.0.913.g12b4baa2536\n\n"},{"id":"447841","messageId":"20220206133026.GB1936@szeder.dev","threadId":"57285","inReplyTo":"patch-v2-2.2-2e2e3569e02-20220202T111228Z-avarab@gmail.com","subject":"Re: [PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2022-02-06T13:30:26Z","receivedAt":"2022-02-06T13:30:33Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Feb 02, 2022 at 12:15:10PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go\n> with the existing GIT_COMPLETION_SHOW_ALL=1 added in\n> c099f579b98 (completion: add GIT_COMPLETION_SHOW_ALL env var,\n> 2020-08-19).\n> \n> This will include plumbing commands such as \"cat-file\" in \"git <TAB>\"\n> and \"git c<TAB>\" completion.\n\nI've tried this a couple of times in the last dozen years or so...\nand ended up hating it every single time, because it too often made\ncompletion of frequently used porcelain commands more cumbersome, and\nquickly reverted it.\n\nSince 6532f3740b (completion: allow to customize the completable\ncommand list, 2018-05-20) it is possible to include and exclude\ncertain commands from the list offered for 'git <TAB>'.  So if you use\nsome plumbing command frequently, then you can add them to the\n'completion.commands' config variable, and they will show up for 'git\n<TAB>', too, without any of the other plumbing commands to get\nannoying.\n\nTo complete only rarely used plumbing commands in a non-intrusive way,\nin my experience, it's best to first attempt to complete only\nporcelains and aliases, and fall back to complete all commands,\nplumbing included, only when no porcelains match the current word to\nbe completed.  E.g.:\n\n  $ git d<TAB>\n  describe   diff   difftool\n  $ git diff-<TAB>\n  diff-files   diff-index   diff-tree\n\n  $ git p<TAB>\n  prune   pull    push    \n  $ git pa<TAB>\n  pack-objects     pack-redundant   pack-refs        patch-id \n\n\n  ---   >8   ---\n\nSubject: [PATCH] completion: list all git commands as fallback\n\n---\n contrib/completion/git-completion.bash | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3edd1cade6..67978e6f22 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3465,6 +3465,9 @@ __git_main ()\n \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n \t\t\telse\n \t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\tif [ ${#COMPREPLY[@]} -eq 0 ]; then\n+\t\t\t\t\t__gitcomp \"$(__git --list-cmds=main,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\tfi\n \t\t\tfi\n \t\t\t;;\n \t\tesac\n-- \n2.35.1.482.g3282949ee0\n\n  ---   8<   ---\n\nI've been using 'completion.commands' and the patch above for a few\nyears now, and this combination worked out the best so far.\n\n> Without/with this I have 134 and 243\n> completion with git <TAB>, respectively.\n\nThose numbers include all your aliases and additional 'git-foo'\ncommands in your PATH; I only get 74 without this patch.  To show the\neffect of this patch I think it would be more relevant to count only\nGit's commands.\n\n\n> It was already possible to do this by tweaking\n> GIT_TESTING_PORCELAIN_COMMAND_LIST= from the outside, that testing\n> variable was added in 84a97131065 (completion: let git provide the\n> completable command list, 2018-05-20). Doing this before loading\n> git-completion.bash worked:\n> \n>     export GIT_TESTING_PORCELAIN_COMMAND_LIST=\"$(git --list-cmds=builtins,main,list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n> \n> But such testing variables are not meant to be used from the outside,\n> and we make no guarantees that those internal won't change. So let's\n> expose this as a dedicated configuration knob.\n> \n> It would be better to teach --list-cmds=* a new category which would\n> include all of these groups, but that's a larger change that we can\n> leave for some other time.\n> \n> 1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/\n> \n> Reported-by: Hongyi Zhao <hongyi.zhao@gmail.com>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 13 ++++++++++-\n>  t/t9902-completion.sh                  | 31 ++++++++++++++++++++++++++\n>  2 files changed, 43 insertions(+), 1 deletion(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 377d6c5494a..2436b8eb6b9 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -49,6 +49,11 @@\n>  #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n>  #     exists).\n>  #\n> +#   GIT_COMPLETION_SHOW_ALL_COMMANDS\n> +#\n> +#     When set to \"1\" suggest all commands, including plumbing commands\n> +#     which are hidden by default (e.g. \"cat-file\" on \"git ca<TAB>\").\n> +#\n>  #   GIT_COMPLETION_SHOW_ALL\n>  #\n>  #     When set to \"1\" suggest all options, including options which are\n> @@ -3455,7 +3460,13 @@ __git_main ()\n>  \t\t\tthen\n>  \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n>  \t\t\telse\n> -\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n> +\t\t\t\tlocal list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config\n> +\n> +\t\t\t\tif test \"${GIT_COMPLETION_SHOW_ALL_COMMANDS-}\" = \"1\"\n> +\t\t\t\tthen\n> +\t\t\t\t\tlist_cmds=builtins,$list_cmds\n> +\t\t\t\tfi\n> +\t\t\t\t__gitcomp \"$(__git --list-cmds=$list_cmds)\"\n>  \t\t\tfi\n>  \t\t\t;;\n>  \t\tesac\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index c9805f2147d..c6d6d6ef896 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -2440,6 +2440,37 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n>  \t)\n>  '\n>  \n> +test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n> +\t(\n> +\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n> +\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n> +\n> +\t\t# Just mainporcelain, not plumbing commands\n> +\t\trun_completion \"git c\" &&\n> +\t\tgrep checkout out &&\n> +\t\t! grep cat-file out\n> +\t)\n> +'\n> +\n> +test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n> +\t(\n> +\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n> +\t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n> +\t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n\nThis variable only affects the completion script itself, but none of\nthe commands invoked by it, so the 'export' is unnecessary.\n\n> +\t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n> +\n> +\t\t# Both mainporcelain and plumbing commands\n> +\t\trun_completion \"git c\" &&\n> +\t\tgrep checkout out &&\n> +\t\tgrep cat-file out &&\n> +\n> +\t\t# Check \"gitk\", a \"main\" command, but not a built-in + more plumbing\n> +\t\trun_completion \"git g\" &&\n> +\t\tgrep gitk out &&\n> +\t\tgrep get-tar-commit-id out\n> +\t)\n> +'\n> +\n>  test_expect_success '__git_complete' '\n>  \tunset -f __git_wrap__git_main &&\n>  \n> -- \n> 2.35.0.913.g12b4baa2536\n> \n"},{"id":"447846","messageId":"xmqq8runiwow.fsf@gitster.g","threadId":"57285","inReplyTo":"20220206133026.GB1936@szeder.dev","subject":"Re: [PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-02-06T20:09:35Z","receivedAt":"2022-02-06T20:09:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> To complete only rarely used plumbing commands in a non-intrusive way,\n> in my experience, it's best to first attempt to complete only\n> porcelains and aliases, and fall back to complete all commands,\n> plumbing included, only when no porcelains match the current word to\n> be completed.  E.g.:\n>\n>   $ git d<TAB>\n>   describe   diff   difftool\n>   $ git diff-<TAB>\n>   diff-files   diff-index   diff-tree\n\nSo after getting\n\n    $ git diff<TAB>\n    diff difftool\n\nyou _have_ to know, if you are not happy with these two, that the\nnext letter in the name of the command you forgot is a dash, to be\nable to say\n\n    $ git diff-<TAB>\n\nwhich is a bit unfortunate, but I agree that it is much nicer than\ngetting all the plumbing when trying to complete \"git d<TAB>\".\n\nI wonder if we can do better, and teach the completion logic an\nability to say this: \"I gave 'diff and difftool' after being asked\nfor 'git diff<TAB>' and then the user is asking the same again\nwithout choosing either. Perhaps I should add less frequent one to\nthe mix\"?\n\nI.e. the end-user session may look like\n\n    $ git diff<TAB>\n    diff difftool\n    $ git diff<TAB>\n    diff difftool diff-files diff-index diff-tree\n\n?\n"},{"id":"447860","messageId":"20220206224740.GD1936@szeder.dev","threadId":"57285","inReplyTo":"xmqq8runiwow.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2022-02-06T22:47:40Z","receivedAt":"2022-02-06T22:47:48Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sun, Feb 06, 2022 at 12:09:35PM -0800, Junio C Hamano wrote:\n> SZEDER Gábor <szeder.dev@gmail.com> writes:\n> \n> > To complete only rarely used plumbing commands in a non-intrusive way,\n> > in my experience, it's best to first attempt to complete only\n> > porcelains and aliases, and fall back to complete all commands,\n> > plumbing included, only when no porcelains match the current word to\n> > be completed.  E.g.:\n> >\n> >   $ git d<TAB>\n> >   describe   diff   difftool\n> >   $ git diff-<TAB>\n> >   diff-files   diff-index   diff-tree\n> \n> So after getting\n> \n>     $ git diff<TAB>\n>     diff difftool\n> \n> you _have_ to know, if you are not happy with these two, that the\n> next letter in the name of the command you forgot is a dash,\n\nYeah, it can only save a couple of keystrokes, but it's not really\nuseful when you want to use it to jog your memory.  I naively assumed\nthat if you use plumbing, then you know what you are doing and which\ncommand you want to execute :)\n\n> to be\n> able to say\n> \n>     $ git diff-<TAB>\n> \n> which is a bit unfortunate, but I agree that it is much nicer than\n> getting all the plumbing when trying to complete \"git d<TAB>\".\n> \n> I wonder if we can do better, and teach the completion logic an\n> ability to say this: \"I gave 'diff and difftool' after being asked\n> for 'git diff<TAB>' and then the user is asking the same again\n> without choosing either. Perhaps I should add less frequent one to\n> the mix\"?\n> \n> I.e. the end-user session may look like\n> \n>     $ git diff<TAB>\n>     diff difftool\n>     $ git diff<TAB>\n>     diff difftool diff-files diff-index diff-tree\n> \n> ?\n\nHrm, interesting, but dunno.  When completing commands in __git_main()\nwe could save the current word to be completed in a variable, and when\ncompleting commands the next time we could check whether the current\nword is still the same, and then include plumbing as well.  However,\nwhen the current word can't be uniquely completed, then we have to\npress TAB twice to get the list of possible completion, so we have to\npreserve the last two current words, and only list plumbing when both\nmatch.\n\n  ---   >8   ---\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 377d6c5494..cda6b48c4e 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3455,8 +3455,17 @@ __git_main ()\n \t\t\tthen\n \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n \t\t\telse\n-\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\techo >>/tmp/COMPLOG \"__git_main() cur: '$cur' last: '$__git_last_command_cur' last2: '$__git_last_command_cur2'\"\n+\t\t\t\tif test \"$cur\" = \"$__git_last_command_cur\" &&\n+\t\t\t\t   test \"$cur\" = \"$__git_last_command_cur2\"\n+\t\t\t\tthen\n+\t\t\t\t\t__gitcomp \"$(__git --list-cmds=main,others,nohelpers,alias,list-complete)\"\n+\t\t\t\telse\n+\t\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\tfi\n \t\t\tfi\n+\t\t\t__git_last_command_cur2=$__git_last_command_cur\n+\t\t\t__git_last_command_cur=$cur\n \t\t\t;;\n \t\tesac\n \t\treturn\n\n  ---   8<   ---\n\nSuperficial testing shows that it appears to work in common cases, but\nwe'll have to think it through when and how to clear these variables.\nE.g.:\n\n  $ git d<TAB><TAB>\n  describe   diff   difftool\n  # Oh, but I wanted to disable the pager\n  $ git --no-p<TAB>\n  # this completes the option uniquely\n  $ git --no-pager d<TAB><TAB>\n  daemon     diff         diff-index   diff-tree\n  describe   diff-files   difftool\n\nI think here it should list only porcelains, but because both those\nlast_cur variables still contain 'd', it lists plumbing as well.\n\nAnd, of course, 'git <TAB><TAB>' in a newly started terminal should\nlist only porcelains, but it lists plumbing as well.\n\n"},{"id":"447867","messageId":"xmqq1r0fjgze.fsf@gitster.g","threadId":"57285","inReplyTo":"20220206224740.GD1936@szeder.dev","subject":"Re: [PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-02-07T07:03:33Z","receivedAt":"2022-02-07T07:06:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> Superficial testing shows that it appears to work in common cases, but\n> we'll have to think it through when and how to clear these variables.\n> E.g.:\n>\n>   $ git d<TAB><TAB>\n>   describe   diff   difftool\n>   # Oh, but I wanted to disable the pager\n>   $ git --no-p<TAB>\n>   # this completes the option uniquely\n>   $ git --no-pager d<TAB><TAB>\n>   daemon     diff         diff-index   diff-tree\n>   describe   diff-files   difftool\n>\n> I think here it should list only porcelains, but because both those\n> last_cur variables still contain 'd', it lists plumbing as well.\n\nYup, it always is tricky to \"invalidate\" a cached value.\n\n"}]}