{"thread":{"id":"53537","subject":"git git<tab> completes non-existent command `git gitk`","startedAt":"2020-05-23T22:26:04Z","lastAt":"2020-05-25T01:54:09Z","messageCount":4,"participants":["Anthony Sottile","Matheus Tavares","Junio C Hamano","Matheus Tavares Bernardino"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"398460","messageId":"CA+dzEBnpheB-ZT5+bajKphux-+7gYFx1Msws7mXM=LOJO7pukw@mail.gmail.com","threadId":"53537","inReplyTo":null,"subject":"git git<tab> completes non-existent command `git gitk`","fromName":"Anthony Sottile","fromEmail":"asottile@umich.edu","sentAt":"2020-05-23T22:25:13Z","receivedAt":"2020-05-23T22:26:04Z","isPatch":false,"sender":{"key":"asottile@umich.edu","avatar":"https://avatars.githubusercontent.com/u/1810591?v=4"},"body":"easiest to reproduce is with docker\n\n```dockerfile\nFROM ubuntu:focal\nRUN : \\\n    && apt-get update \\\n    && DEBIAN_FRONTEND=noninteractive apt-get install -y\n--no-install-recommends \\\n        bash-completion \\\n        git \\\n    && apt-get clean \\\n    && rm -rf /var/lib/apt/lists/*\n```\n\n```console\n$ docker run --rm -ti test bash\nroot@23e691ecc7ba:/# [ -f /etc/bash_completion ] && . /etc/bash_completion\nroot@23e691ecc7ba:/# git gitk\n```\n\n(I typed git git<tab>)\n\n```console\n$ git gitk\ngit: 'gitk' is not a git command. See 'git --help'.\n```\n\nthis is a bit annoying because I have some aliases/commands for git-github-*\n\nthe git version I have is 2.25.1:\n\n```console\n$ git --version\ngit version 2.25.1\n```\n\nAnthony\n"},{"id":"398477","messageId":"20200524213808.24849-1-matheus.bernardino@usp.br","threadId":"53537","inReplyTo":"CA+dzEBnpheB-ZT5+bajKphux-+7gYFx1Msws7mXM=LOJO7pukw@mail.gmail.com","subject":"Re: git git<tab> completes non-existent command `git gitk`","fromName":"Matheus Tavares","fromEmail":"matheus.bernardino@usp.br","sentAt":"2020-05-24T21:38:08Z","receivedAt":"2020-05-24T21:38:28Z","isPatch":false,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"Hi, Anthony\n\nOn Sat, May 23, 2020 at 7:25 PM Anthony Sottile <asottile@umich.edu> wrote:\n>\n> easiest to reproduce is with docker\n>\n> ```dockerfile\n> FROM ubuntu:focal\n> RUN : \\\n>     && apt-get update \\\n>     && DEBIAN_FRONTEND=noninteractive apt-get install -y\n> --no-install-recommends \\\n>         bash-completion \\\n>         git \\\n>     && apt-get clean \\\n>     && rm -rf /var/lib/apt/lists/*\n> ```\n>\n> ```console\n> $ docker run --rm -ti test bash\n> root@23e691ecc7ba:/# [ -f /etc/bash_completion ] && . /etc/bash_completion\n> root@23e691ecc7ba:/# git gitk\n> ```\n>\n> (I typed git git<tab>)\n>\n> ```console\n> $ git gitk\n> git: 'gitk' is not a git command. See 'git --help'.\n> ```\n> this is a bit annoying because I have some aliases/commands for git-github-*\n>\n> the git version I have is 2.25.1:\n\nThanks for the report. This is also reproducible in Git 2.27.0-rc1. To complete\nsubcommands, git-completion.bash uses[1] the output of:\n\n\tgit --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config\n\nAnd the list returned by the line above contains \"gitk\", because this\ncommand is in the \"mainporcelain\" category (in command-list.txt).\n\nOne possible solution to the invalid completion you mentioned, without having\nto re-categorize \"gitk\", is to explicitly exclude it in git-completion.bash:\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b1d6e5ebed..f07394584f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3214,7 +3214,10 @@ __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 cmds=\"$(__git --list-cmds=list-mainporcelain,others,nohelpers,list-complete,config | \\\n+\t\t\t\t\t\tsed -e '/^gitk$/d')\"\n+\t\t\t\tlocal aliases=\"$(__git --list-cmds=alias,config)\"\n+\t\t\t\t__gitcomp \"$cmds $aliases\"\n \t\t\tfi\n \t\t\t;;\n \t\tesac\n\n(I had to split the list into \"cmds\" and \"aliases\" so that we could still give\ncompletion for a valid \"git gitk\" alias, if present.)\n\nThis should solve the problem, althought it's admittedly not very elegant...\nNevertheless, I'd be happy to send a complete patch if folks are happy with the\nworkaround.\n\nIn the meantime, you could use:\n\n\tgit config completion.commands -gitk\n\nTo locally remove the completion for \"gitk\".\n\nThanks,\nMatheus\n\n[1]: See contrib/completion/git-completion.bash +3218\n     (https://github.com/git/git/blob/master/contrib/completion/git-completion.bash#L3218)\n"},{"id":"398480","messageId":"xmqqlflgq2nr.fsf@gitster.c.googlers.com","threadId":"53537","inReplyTo":"20200524213808.24849-1-matheus.bernardino@usp.br","subject":"Re: git git<tab> completes non-existent command `git gitk`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-25T00:27:52Z","receivedAt":"2020-05-25T00:27:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matheus Tavares <matheus.bernardino@usp.br> writes:\n\n> This should solve the problem, althought it's admittedly not very elegant...\n> Nevertheless, I'd be happy to send a complete patch if folks are happy with the\n> workaround.\n\nPlease don't.\n\n> In the meantime, you could use:\n>\n> \tgit config completion.commands -gitk\n>\n> To locally remove the completion for \"gitk\".\n\nI think an equivalent of this in-core would be the way to go.  I\nwonder if there are any commands other than gitk that cannot be\ninvoked as a subcommand of \"git\" potty.\n\nt/t9902-completion.sh would be a good place to test this.\n"},{"id":"398481","messageId":"CAHd-oW7b2191haSeoaBu4jvS+PBG04RKGxOhp7+rRQF+b9eErg@mail.gmail.com","threadId":"53537","inReplyTo":"xmqqlflgq2nr.fsf@gitster.c.googlers.com","subject":"Re: git git<tab> completes non-existent command `git gitk`","fromName":"Matheus Tavares Bernardino","fromEmail":"matheus.bernardino@usp.br","sentAt":"2020-05-25T01:53:53Z","receivedAt":"2020-05-25T01:54:09Z","isPatch":false,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"On Sun, May 24, 2020 at 9:27 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Matheus Tavares <matheus.bernardino@usp.br> writes:\n>\n> > In the meantime, you could use:\n> >\n> >       git config completion.commands -gitk\n> >\n> > To locally remove the completion for \"gitk\".\n>\n> I think an equivalent of this in-core would be the way to go.\n\nI'm not sure I understand the idea, but would that be something along\nthese lines? Adding a \"nocomplete\" category in commands-list.txt, to\ndo the opposite of the \"complete\" we already have[1]. Then adding a\nnew group name to \"--list-cmds\" (such as \"--list-cmds=completeonly\"),\nwhich would include the commands that are in \"complete\" and exclude\nthose in \"nocomplete\"? We then might be able to complete subcommands\nwith the output of:\n\ngit --list-cmds=list-mainporcelain,others,nohelpers,alias,completeonly,config\n\n[1]: \"nocomplete\" would only be relevant in conjunction with\n\"list-mainporcelain\", as the commands in the latter (as gitk) are\ncurrently completed by default (even without \"complete\").\n\n> I wonder if there are any commands other than gitk that cannot be\n> invoked as a subcommand of \"git\" potty.\n\nIn the list suggested by git-completion, I think gitk is the only one\n(if I haven't missed any).\n"}]}