diff mbox series

completion: handle other variants of "branch -m"

Message ID YBsOzixRy0ahWaLN@coredump.intra.peff.net (mailing list archive)
State Accepted
Commit bca362c1f94164f23e1c9b5cf833804d46315cbe
Headers show
Series completion: handle other variants of "branch -m" | expand

Commit Message

Jeff King Feb. 3, 2021, 8:59 p.m. UTC
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 mbox series

Patch

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