Bash completion suggests tags for git branch -D

3 messages, 2 authors, 2021-02-02 · open the first message on its own page

Bash completion suggests tags for git branch -D

From: Paul Jolly <hidden>
Date: 2021-02-02 06:03:18

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

Re: Bash completion suggests tags for git branch -D

From: Jeff King <hidden>
Date: 2021-02-02 09:03:36

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

Re: Bash completion suggests tags for git branch -D

From: Jeff King <hidden>
Date: 2021-02-02 09:24:12

On Tue, Feb 02, 2021 at 04:02:13AM -0500, Jeff King wrote:
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. :)

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help