Re: Bash completion suggests tags for git branch -D

Subsystems: the rest

6 messages, 5 authors, 2021-02-03 · open the first message on its own page

Re: Bash completion suggests tags for git branch -D

From: Junio C Hamano <hidden>
Date: 2021-02-02 17:19:47

Jeff King [off-list ref] writes:
On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:
quoted
quoted
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 <redacted>
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
 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

Re: Bash completion suggests tags for git branch -D

From: Eric Sunshine <hidden>
Date: 2021-02-02 17:29:52

On Tue, Feb 2, 2021 at 12:22 PM Junio C Hamano [off-list ref] wrote:
From: Jeff King <redacted>
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
Perhaps a Reported-by: would be appropriate?

Re: Bash completion suggests tags for git branch -D

From: Jeff King <hidden>
Date: 2021-02-02 19:40:09

On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:
quoted
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 <redacted>
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
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

Re: Bash completion suggests tags for git branch -D

From: Paul Jolly <hidden>
Date: 2021-02-02 20:28:29

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.
Thanks for the many replies and quick fix.

Just to flag another issue that I raised that's in the same space of
bash completions:

https://lore.kernel.org/git/CACoUkn7D52ox2MgUfS2uQtLa28twccfxnQnUteVV_yFfVLFQdQ@mail.gmail.com/

That, however, might be more tricky?

Thanks,


Paul

Re: Bash completion suggests tags for git branch -D

From: SZEDER Gábor <hidden>
Date: 2021-02-03 20:01:35

On Tue, Feb 02, 2021 at 09:14:39AM -0800, Junio C Hamano wrote:
From: Jeff King <redacted>
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.
quoted hunk
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
 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

[PATCH] completion: handle other variants of "branch -m"

From: Jeff King <hidden>
Date: 2021-02-03 21:01:06

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:
quoted
From: Jeff King <redacted>
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 <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help