{"thread":{"id":"55090","subject":"Bash completion suggests tags for git branch -D","startedAt":"2021-02-02T06:03:18Z","lastAt":"2021-02-03T21:01:06Z","messageCount":10,"participants":["Paul Jolly","Jeff King","Junio C Hamano","Eric Sunshine","SZEDER Gábor"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"415886","messageId":"CACoUkn6+9C3+HVVQF905t1siAD9Sqo1JvRa0Whw-J6x7V7icyg@mail.gmail.com","threadId":"55090","inReplyTo":null,"subject":"Bash completion suggests tags for git branch -D","fromName":"Paul Jolly","fromEmail":"paul@myitcv.io","sentAt":"2021-02-02T06:01:07Z","receivedAt":"2021-02-02T06:03:18Z","isPatch":false,"sender":{"key":"paul@myitcv.io","avatar":"https://gravatar.com/avatar/6a83179b2ef0386af693cc03a9c50ea897f5246c5dcc0fa5d126171ba17c3a63?d=mp&s=160"},"body":"Hi,\n\nEasiest explained via a repro:\n\n    cd $(mktemp -d)\n    git init\n    touch README\n    git add -A\n    git commit -am 'Initial commit'\n    git checkout -b branch\n    git tag b-is-a-tag\n\nIf you then type:\n\n    git branch -D b^\n\nleaving the cursor at the position shown by the caret, then attempt\ncompletion via <Tab><Tab> (at least according to my bash setup) two\noptions are shown:\n\n    b-is-a-tag   branch\n\nb-is-a-tag is not a branch, so should not be offered as a completion\ncandidate in this instance.\n\nMany thanks,\n\n\nPaul\n"},{"id":"415892","messageId":"YBkVFTOP6K1//i6m@coredump.intra.peff.net","threadId":"55090","inReplyTo":"CACoUkn6+9C3+HVVQF905t1siAD9Sqo1JvRa0Whw-J6x7V7icyg@mail.gmail.com","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-02-02T09:02:13Z","receivedAt":"2021-02-02T09:03:36Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 02, 2021 at 06:01:07AM +0000, Paul Jolly wrote:\n\n> Easiest explained via a repro:\n> \n>     cd $(mktemp -d)\n>     git init\n>     touch README\n>     git add -A\n>     git commit -am 'Initial commit'\n>     git checkout -b branch\n>     git tag b-is-a-tag\n> \n> If you then type:\n> \n>     git branch -D b^\n> \n> leaving the cursor at the position shown by the caret, then attempt\n> completion via <Tab><Tab> (at least according to my bash setup) two\n> options are shown:\n> \n>     b-is-a-tag   branch\n> \n> b-is-a-tag is not a branch, so should not be offered as a completion\n> candidate in this instance.\n\nIt looks like lowercase \"-d\" works. So maybe the \"-d\" here:\n\n  $ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head \n  _git_branch ()\n  {\n  \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n  \n  \twhile [ $c -lt $cword ]; do\n  \t\ti=\"${words[c]}\"\n  \t\tcase \"$i\" in\n  \t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n  \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n  \t\tesac\n\njust needs to look for \"-D\", too?\n\n-Peff\n"},{"id":"415895","messageId":"YBkZnY8X5VyNkXkR@coredump.intra.peff.net","threadId":"55090","inReplyTo":"YBkVFTOP6K1//i6m@coredump.intra.peff.net","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-02-02T09:21:33Z","receivedAt":"2021-02-02T09:24:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:\n\n> > b-is-a-tag is not a branch, so should not be offered as a completion\n> > candidate in this instance.\n> \n> It looks like lowercase \"-d\" works. So maybe the \"-d\" here:\n> \n>   $ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head \n>   _git_branch ()\n>   {\n>   \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n>   \n>   \twhile [ $c -lt $cword ]; do\n>   \t\ti=\"${words[c]}\"\n>   \t\tcase \"$i\" in\n>   \t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n>   \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n>   \t\tesac\n> \n> just needs to look for \"-D\", too?\n\nOops. I meant to paste the \"before\" snippet, but this is obviously after\nI stuck \"-D\" in there. It does seem to work. :)\n\n-Peff\n"},{"id":"415939","messageId":"xmqqpn1igznk.fsf@gitster.c.googlers.com","threadId":"55090","inReplyTo":"YBkZnY8X5VyNkXkR@coredump.intra.peff.net","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-02-02T17:14:39Z","receivedAt":"2021-02-02T17:19:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:\n>\n>> > b-is-a-tag is not a branch, so should not be offered as a completion\n>> > candidate in this instance.\n>> \n>> It looks like lowercase \"-d\" works. So maybe the \"-d\" here:\n>> \n>>   $ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head \n>>   _git_branch ()\n>>   {\n>>   \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n>>   \n>>   \twhile [ $c -lt $cword ]; do\n>>   \t\ti=\"${words[c]}\"\n>>   \t\tcase \"$i\" in\n>>   \t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n>>   \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n>>   \t\tesac\n>> \n>> just needs to look for \"-D\", too?\n>\n> Oops. I meant to paste the \"before\" snippet, but this is obviously after\n> I stuck \"-D\" in there. It does seem to work. :)\n\n;-)\n\nBefore we forget, as you said a few times that everything you send\nhere on Git are signed off...\n\n-- >8 --\nFrom: Jeff King <peff@peff.net>\nDate: Tue Feb 2 04:02:13 2021 -0500\nSubject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n\nPaul Jolly noticed that the former offers not just branches but tags\nas completion candidates.  Mimic how \"branch -d\" limits its suggestion\nto branch names.\n\nSigned-off-by: Jeff King <peff@peff.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 4b1f4264a6..b54113e2f9 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1447,7 +1447,7 @@ _git_branch ()\n \twhile [ $c -lt $cword ]; do\n \t\ti=\"${words[c]}\"\n \t\tcase \"$i\" in\n-\t\t-d|--delete|-m|--move)\tonly_local_ref=\"y\" ;;\n+\t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n \t\tesac\n \t\t((c++))\n-- \n2.30.0-586-g047f30a795\n\n"},{"id":"415942","messageId":"CAPig+cQoCuQSyrKfE_sNCvi=Yo2035e0TOA1sOBF1HE02-kFjA@mail.gmail.com","threadId":"55090","inReplyTo":"xmqqpn1igznk.fsf@gitster.c.googlers.com","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-02-02T17:24:51Z","receivedAt":"2021-02-02T17:29:52Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Feb 2, 2021 at 12:22 PM Junio C Hamano <gitster@pobox.com> wrote:\n> From: Jeff King <peff@peff.net>\n> Subject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n>\n> Paul Jolly noticed that the former offers not just branches but tags\n> as completion candidates.  Mimic how \"branch -d\" limits its suggestion\n> to branch names.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nPerhaps a Reported-by: would be appropriate?\n"},{"id":"415949","messageId":"YBmqT/hvT9wM6yHz@coredump.intra.peff.net","threadId":"55090","inReplyTo":"xmqqpn1igznk.fsf@gitster.c.googlers.com","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-02-02T19:38:55Z","receivedAt":"2021-02-02T19:40:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:\n\n> > Oops. I meant to paste the \"before\" snippet, but this is obviously after\n> > I stuck \"-D\" in there. It does seem to work. :)\n> \n> ;-)\n> \n> Before we forget, as you said a few times that everything you send\n> here on Git are signed off...\n> \n> -- >8 --\n> From: Jeff King <peff@peff.net>\n> Date: Tue Feb 2 04:02:13 2021 -0500\n> Subject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n> \n> Paul Jolly noticed that the former offers not just branches but tags\n> as completion candidates.  Mimic how \"branch -d\" limits its suggestion\n> to branch names.\n> \n> Signed-off-by: Jeff King <peff@peff.net>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nYeah, this looks fine (though Eric's reported-by suggestion seems\nreasonable). I endorse the signoff. :)\n\nI had also considered whether a test made sense, but I wasn't at all\nfamiliar with the completion tests. It looks like we're not even testing\n\"-d\", so I'm happy to proceed without one.\n\n-Peff\n"},{"id":"415957","messageId":"CACoUkn4AK1uvOwfkU-adrsoCFwAbEow=owN7kTeyc5hoASAUTA@mail.gmail.com","threadId":"55090","inReplyTo":"YBmqT/hvT9wM6yHz@coredump.intra.peff.net","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Paul Jolly","fromEmail":"paul@myitcv.io","sentAt":"2021-02-02T20:25:07Z","receivedAt":"2021-02-02T20:28:29Z","isPatch":false,"sender":{"key":"paul@myitcv.io","avatar":"https://gravatar.com/avatar/6a83179b2ef0386af693cc03a9c50ea897f5246c5dcc0fa5d126171ba17c3a63?d=mp&s=160"},"body":"> I had also considered whether a test made sense, but I wasn't at all\n> familiar with the completion tests. It looks like we're not even testing\n> \"-d\", so I'm happy to proceed without one.\n\nThanks for the many replies and quick fix.\n\nJust to flag another issue that I raised that's in the same space of\nbash completions:\n\nhttps://lore.kernel.org/git/CACoUkn7D52ox2MgUfS2uQtLa28twccfxnQnUteVV_yFfVLFQdQ@mail.gmail.com/\n\nThat, however, might be more tricky?\n\nThanks,\n\n\nPaul\n"},{"id":"415962","messageId":"xmqqlfc6f99m.fsf@gitster.c.googlers.com","threadId":"55090","inReplyTo":"CAPig+cQoCuQSyrKfE_sNCvi=Yo2035e0TOA1sOBF1HE02-kFjA@mail.gmail.com","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-02-02T21:29:57Z","receivedAt":"2021-02-02T21:30:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Tue, Feb 2, 2021 at 12:22 PM Junio C Hamano <gitster@pobox.com> wrote:\n>> From: Jeff King <peff@peff.net>\n>> Subject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n>>\n>> Paul Jolly noticed that the former offers not just branches but tags\n>> as completion candidates.  Mimic how \"branch -d\" limits its suggestion\n>> to branch names.\n>>\n>> Signed-off-by: Jeff King <peff@peff.net>\n>> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>\n> Perhaps a Reported-by: would be appropriate?\n\nComparing the way I wrote the above, and a bland description of\n\"this is broken how\" plus \"Reported-by:\", I personally feel the\nformer gives the credit in a more proper way, but if more people\nprefer the more mechanical style, I can adjust.\n\nHere is what I queued.\n\n--- >8 ------ >8 ------ >8 ------ >8 ------ >8 ---\nFrom: Jeff King <peff@peff.net>\nDate: Tue, 2 Feb 2021 04:02:13 -0500\nSubject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n\nThe former offers not just branches but tags as completion\ncandidates.\n\nMimic how \"branch -d\" limits its suggestion to branch names.\n\nReported-by: Paul Jolly <paul@myitcv.io>\nSigned-off-by: Jeff King <peff@peff.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 463a3124da..ba950a247d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1438,7 +1438,7 @@ _git_branch ()\n \twhile [ $c -lt $cword ]; do\n \t\ti=\"${words[c]}\"\n \t\tcase \"$i\" in\n-\t\t-d|--delete|-m|--move)\tonly_local_ref=\"y\" ;;\n+\t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n \t\tesac\n \t\t((c++))\n-- \n2.30.0-586-g047f30a795\n\n"},{"id":"416082","messageId":"20210203200047.GB1036595@szeder.dev","threadId":"55090","inReplyTo":"xmqqpn1igznk.fsf@gitster.c.googlers.com","subject":"Re: Bash completion suggests tags for git branch -D","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-02-03T20:00:47Z","receivedAt":"2021-02-03T20:01:35Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:\n> From: Jeff King <peff@peff.net>\n> Date: Tue Feb 2 04:02:13 2021 -0500\n> Subject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n> \n> Paul Jolly noticed that the former offers not just branches but tags\n> as completion candidates.  Mimic how \"branch -d\" limits its suggestion\n> to branch names.\n\nUh-oh.  This is a bug from my second ever commit in Git! ;)\n\n'-M' should be handled the same.\n\n> Signed-off-by: Jeff King <peff@peff.net>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  contrib/completion/git-completion.bash | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 4b1f4264a6..b54113e2f9 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1447,7 +1447,7 @@ _git_branch ()\n>  \twhile [ $c -lt $cword ]; do\n>  \t\ti=\"${words[c]}\"\n>  \t\tcase \"$i\" in\n> -\t\t-d|--delete|-m|--move)\tonly_local_ref=\"y\" ;;\n> +\t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n>  \t\t-r|--remotes)\t\thas_r=\"y\" ;;\n>  \t\tesac\n>  \t\t((c++))\n> -- \n> 2.30.0-586-g047f30a795\n> \n"},{"id":"416089","messageId":"YBsOzixRy0ahWaLN@coredump.intra.peff.net","threadId":"55090","inReplyTo":"20210203200047.GB1036595@szeder.dev","subject":"[PATCH] completion: handle other variants of \"branch -m\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-02-03T20:59:58Z","receivedAt":"2021-02-03T21:01:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 03, 2021 at 09:00:47PM +0100, SZEDER Gábor wrote:\n\n> On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:\n> > From: Jeff King <peff@peff.net>\n> > Date: Tue Feb 2 04:02:13 2021 -0500\n> > Subject: [PATCH] completion: treat \"branch -D\" the same way as \"branch -d\"\n> > \n> > Paul Jolly noticed that the former offers not just branches but tags\n> > as completion candidates.  Mimic how \"branch -d\" limits its suggestion\n> > to branch names.\n> \n> Uh-oh.  This is a bug from my second ever commit in Git! ;)\n> \n> '-M' should be handled the same.\n\nOh, indeed. Maybe this?\n\n-- >8 --\nSubject: [PATCH] completion: handle other variants of \"branch -m\"\n\nWe didn't special-case \"branch -M\" (with a capital M) the same as\n\"branch -m\", nor any of the \"--copy\" variants. As a result these offered\nany ref as the next candidate, and not just branch names.\n\nNote that I rewrapped case-arm line since it's now quite long, and\nlikewise the one below it for consistency. I also re-ordered the\nexisting \"-D\" to make it more obvious how the cases group together.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nWe could also squash the whole thing together with the earlier \"-D\" as a\nsingle fix, but it's all trivial enough that I'm not sure it's worth\nspending a lot of time polishing.\n\n contrib/completion/git-completion.bash | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ba950a247d..567e73837a 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1438,8 +1438,10 @@ _git_branch ()\n \twhile [ $c -lt $cword ]; do\n \t\ti=\"${words[c]}\"\n \t\tcase \"$i\" in\n-\t\t-d|--delete|-D|-m|--move)\tonly_local_ref=\"y\" ;;\n-\t\t-r|--remotes)\t\thas_r=\"y\" ;;\n+\t\t-d|-D|--delete|-m|-M|--move|-c|-C|--copy)\n+\t\t\tonly_local_ref=\"y\" ;;\n+\t\t-r|--remotes)\n+\t\t\thas_r=\"y\" ;;\n \t\tesac\n \t\t((c++))\n \tdone\n-- \n2.30.0.882.gf229bd7cc9\n\n"}]}