* Bash completion suggests tags for git branch -D
@ 2021-02-02 6:01 Paul Jolly
2021-02-02 9:02 ` Jeff King
0 siblings, 1 reply; 10+ messages in thread
From: Paul Jolly @ 2021-02-02 6:01 UTC (permalink / raw)
To: git
Hi,
Easiest explained via a repro:
cd $(mktemp -d)
git init
touch README
git add -A
git commit -am 'Initial commit'
git checkout -b branch
git tag b-is-a-tag
If you then type:
git branch -D b^
leaving the cursor at the position shown by the caret, then attempt
completion via <Tab><Tab> (at least according to my bash setup) two
options are shown:
b-is-a-tag branch
b-is-a-tag is not a branch, so should not be offered as a completion
candidate in this instance.
Many thanks,
Paul
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 6:01 Bash completion suggests tags for git branch -D Paul Jolly
@ 2021-02-02 9:02 ` Jeff King
2021-02-02 9:21 ` Jeff King
0 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-02-02 9:02 UTC (permalink / raw)
To: Paul Jolly; +Cc: git
On Tue, Feb 02, 2021 at 06:01:07AM +0000, Paul Jolly wrote:
> Easiest explained via a repro:
>
> cd $(mktemp -d)
> git init
> touch README
> git add -A
> git commit -am 'Initial commit'
> git checkout -b branch
> git tag b-is-a-tag
>
> If you then type:
>
> git branch -D b^
>
> leaving the cursor at the position shown by the caret, then attempt
> completion via <Tab><Tab> (at least according to my bash setup) two
> options are shown:
>
> b-is-a-tag branch
>
> b-is-a-tag is not a branch, so should not be offered as a completion
> candidate in this instance.
It looks like lowercase "-d" works. So maybe the "-d" here:
$ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head
_git_branch ()
{
local i c=1 only_local_ref="n" has_r="n"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-d|--delete|-D|-m|--move) only_local_ref="y" ;;
-r|--remotes) has_r="y" ;;
esac
just needs to look for "-D", too?
-Peff
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 9:02 ` Jeff King
@ 2021-02-02 9:21 ` Jeff King
2021-02-02 17:14 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-02-02 9:21 UTC (permalink / raw)
To: Paul Jolly; +Cc: git
On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:
> > b-is-a-tag is not a branch, so should not be offered as a completion
> > candidate in this instance.
>
> It looks like lowercase "-d" works. So maybe the "-d" here:
>
> $ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head
> _git_branch ()
> {
> local i c=1 only_local_ref="n" has_r="n"
>
> while [ $c -lt $cword ]; do
> i="${words[c]}"
> case "$i" in
> -d|--delete|-D|-m|--move) only_local_ref="y" ;;
> -r|--remotes) has_r="y" ;;
> esac
>
> just needs to look for "-D", too?
Oops. I meant to paste the "before" snippet, but this is obviously after
I stuck "-D" in there. It does seem to work. :)
-Peff
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 9:21 ` Jeff King
@ 2021-02-02 17:14 ` Junio C Hamano
2021-02-02 17:24 ` Eric Sunshine
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Junio C Hamano @ 2021-02-02 17:14 UTC (permalink / raw)
To: Jeff King; +Cc: Paul Jolly, git
Jeff King <peff@peff.net> writes:
> On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:
>
>> > b-is-a-tag is not a branch, so should not be offered as a completion
>> > candidate in this instance.
>>
>> It looks like lowercase "-d" works. So maybe the "-d" here:
>>
>> $ sed -n '/git_branch/,/^}/p' contrib/completion/git-completion.bash | head
>> _git_branch ()
>> {
>> local i c=1 only_local_ref="n" has_r="n"
>>
>> while [ $c -lt $cword ]; do
>> i="${words[c]}"
>> case "$i" in
>> -d|--delete|-D|-m|--move) only_local_ref="y" ;;
>> -r|--remotes) has_r="y" ;;
>> esac
>>
>> just needs to look for "-D", too?
>
> Oops. I meant to paste the "before" snippet, but this is obviously after
> I stuck "-D" in there. It does seem to work. :)
;-)
Before we forget, as you said a few times that everything you send
here on Git are signed off...
-- >8 --
From: Jeff King <peff@peff.net>
Date: Tue Feb 2 04:02:13 2021 -0500
Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
Paul Jolly noticed that the former offers not just branches but tags
as completion candidates. Mimic how "branch -d" limits its suggestion
to branch names.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
contrib/completion/git-completion.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4b1f4264a6..b54113e2f9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1447,7 +1447,7 @@ _git_branch ()
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- -d|--delete|-m|--move) only_local_ref="y" ;;
+ -d|--delete|-D|-m|--move) only_local_ref="y" ;;
-r|--remotes) has_r="y" ;;
esac
((c++))
--
2.30.0-586-g047f30a795
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 17:14 ` Junio C Hamano
@ 2021-02-02 17:24 ` Eric Sunshine
2021-02-02 21:29 ` Junio C Hamano
2021-02-02 19:38 ` Jeff King
2021-02-03 20:00 ` SZEDER Gábor
2 siblings, 1 reply; 10+ messages in thread
From: Eric Sunshine @ 2021-02-02 17:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, Paul Jolly, Git List
On Tue, Feb 2, 2021 at 12:22 PM Junio C Hamano <gitster@pobox.com> wrote:
> From: Jeff King <peff@peff.net>
> Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
>
> Paul Jolly noticed that the former offers not just branches but tags
> as completion candidates. Mimic how "branch -d" limits its suggestion
> to branch names.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Perhaps a Reported-by: would be appropriate?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 17:24 ` Eric Sunshine
@ 2021-02-02 21:29 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2021-02-02 21:29 UTC (permalink / raw)
To: Eric Sunshine; +Cc: Jeff King, Paul Jolly, Git List
Eric Sunshine <sunshine@sunshineco.com> writes:
> On Tue, Feb 2, 2021 at 12:22 PM Junio C Hamano <gitster@pobox.com> wrote:
>> From: Jeff King <peff@peff.net>
>> Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
>>
>> Paul Jolly noticed that the former offers not just branches but tags
>> as completion candidates. Mimic how "branch -d" limits its suggestion
>> to branch names.
>>
>> Signed-off-by: Jeff King <peff@peff.net>
>> Signed-off-by: Junio C Hamano <gitster@pobox.com>
>
> Perhaps a Reported-by: would be appropriate?
Comparing the way I wrote the above, and a bland description of
"this is broken how" plus "Reported-by:", I personally feel the
former gives the credit in a more proper way, but if more people
prefer the more mechanical style, I can adjust.
Here is what I queued.
--- >8 ------ >8 ------ >8 ------ >8 ------ >8 ---
From: Jeff King <peff@peff.net>
Date: Tue, 2 Feb 2021 04:02:13 -0500
Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
The former offers not just branches but tags as completion
candidates.
Mimic how "branch -d" limits its suggestion to branch names.
Reported-by: Paul Jolly <paul@myitcv.io>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
contrib/completion/git-completion.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 463a3124da..ba950a247d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1438,7 +1438,7 @@ _git_branch ()
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- -d|--delete|-m|--move) only_local_ref="y" ;;
+ -d|--delete|-D|-m|--move) only_local_ref="y" ;;
-r|--remotes) has_r="y" ;;
esac
((c++))
--
2.30.0-586-g047f30a795
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 17:14 ` Junio C Hamano
2021-02-02 17:24 ` Eric Sunshine
@ 2021-02-02 19:38 ` Jeff King
2021-02-02 20:25 ` Paul Jolly
2021-02-03 20:00 ` SZEDER Gábor
2 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-02-02 19:38 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Paul Jolly, git
On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:
> > Oops. I meant to paste the "before" snippet, but this is obviously after
> > I stuck "-D" in there. It does seem to work. :)
>
> ;-)
>
> Before we forget, as you said a few times that everything you send
> here on Git are signed off...
>
> -- >8 --
> From: Jeff King <peff@peff.net>
> Date: Tue Feb 2 04:02:13 2021 -0500
> Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
>
> Paul Jolly noticed that the former offers not just branches but tags
> as completion candidates. Mimic how "branch -d" limits its suggestion
> to branch names.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Yeah, this looks fine (though Eric's reported-by suggestion seems
reasonable). I endorse the signoff. :)
I had also considered whether a test made sense, but I wasn't at all
familiar with the completion tests. It looks like we're not even testing
"-d", so I'm happy to proceed without one.
-Peff
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Bash completion suggests tags for git branch -D
2021-02-02 17:14 ` Junio C Hamano
2021-02-02 17:24 ` Eric Sunshine
2021-02-02 19:38 ` Jeff King
@ 2021-02-03 20:00 ` SZEDER Gábor
2021-02-03 20:59 ` [PATCH] completion: handle other variants of "branch -m" Jeff King
2 siblings, 1 reply; 10+ messages in thread
From: SZEDER Gábor @ 2021-02-03 20:00 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, Paul Jolly, git
On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:
> From: Jeff King <peff@peff.net>
> Date: Tue Feb 2 04:02:13 2021 -0500
> Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
>
> Paul Jolly noticed that the former offers not just branches but tags
> as completion candidates. Mimic how "branch -d" limits its suggestion
> to branch names.
Uh-oh. This is a bug from my second ever commit in Git! ;)
'-M' should be handled the same.
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> contrib/completion/git-completion.bash | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 4b1f4264a6..b54113e2f9 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1447,7 +1447,7 @@ _git_branch ()
> while [ $c -lt $cword ]; do
> i="${words[c]}"
> case "$i" in
> - -d|--delete|-m|--move) only_local_ref="y" ;;
> + -d|--delete|-D|-m|--move) only_local_ref="y" ;;
> -r|--remotes) has_r="y" ;;
> esac
> ((c++))
> --
> 2.30.0-586-g047f30a795
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] completion: handle other variants of "branch -m"
2021-02-03 20:00 ` SZEDER Gábor
@ 2021-02-03 20:59 ` Jeff King
0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2021-02-03 20:59 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Junio C Hamano, Paul Jolly, git
On Wed, Feb 03, 2021 at 09:00:47PM +0100, SZEDER Gábor wrote:
> On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:
> > From: Jeff King <peff@peff.net>
> > Date: Tue Feb 2 04:02:13 2021 -0500
> > Subject: [PATCH] completion: treat "branch -D" the same way as "branch -d"
> >
> > Paul Jolly noticed that the former offers not just branches but tags
> > as completion candidates. Mimic how "branch -d" limits its suggestion
> > to branch names.
>
> Uh-oh. This is a bug from my second ever commit in Git! ;)
>
> '-M' should be handled the same.
Oh, indeed. Maybe this?
-- >8 --
Subject: [PATCH] completion: handle other variants of "branch -m"
We didn't special-case "branch -M" (with a capital M) the same as
"branch -m", nor any of the "--copy" variants. As a result these offered
any ref as the next candidate, and not just branch names.
Note that I rewrapped case-arm line since it's now quite long, and
likewise the one below it for consistency. I also re-ordered the
existing "-D" to make it more obvious how the cases group together.
Signed-off-by: Jeff King <peff@peff.net>
---
We could also squash the whole thing together with the earlier "-D" as a
single fix, but it's all trivial enough that I'm not sure it's worth
spending a lot of time polishing.
contrib/completion/git-completion.bash | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ba950a247d..567e73837a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1438,8 +1438,10 @@ _git_branch ()
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- -d|--delete|-D|-m|--move) only_local_ref="y" ;;
- -r|--remotes) has_r="y" ;;
+ -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
+ only_local_ref="y" ;;
+ -r|--remotes)
+ has_r="y" ;;
esac
((c++))
done
--
2.30.0.882.gf229bd7cc9
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-02-03 21:02 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 6:01 Bash completion suggests tags for git branch -D Paul Jolly
2021-02-02 9:02 ` Jeff King
2021-02-02 9:21 ` Jeff King
2021-02-02 17:14 ` Junio C Hamano
2021-02-02 17:24 ` Eric Sunshine
2021-02-02 21:29 ` Junio C Hamano
2021-02-02 19:38 ` Jeff King
2021-02-02 20:25 ` Paul Jolly
2021-02-03 20:00 ` SZEDER Gábor
2021-02-03 20:59 ` [PATCH] completion: handle other variants of "branch -m" Jeff King
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).