prezto icon indicating copy to clipboard operation
prezto copied to clipboard

`git push -d origin bran<TAB>` autocomplete suggests `origin/branch` instead of `branch`

Open nyanpasu64 opened this issue 5 years ago • 7 comments

Description

If I want to delete branch which exists on a remote origin, and I type git push -d origin bran... and press Tab, autocomplete suggests origin/branch.

Expected behavior

Autocomplete should suggest branch.

Actual behavior

Autocomplete suggests origin/branch. If branch does not exist locally, pressing Enter fails with a confusing error:

error: unable to delete 'origin/branch': remote ref does not exist
error: failed to push some refs to 'https://github.com/jimbo1qaz/...git'

Steps to Reproduce

  1. Install prezto, enable git plugin, and cd to a local Git repo.
  2. Create a branch which exists only remotely. (a. push local branch, then delete local branch) (create PR through github's web-based file editor)
  3. Locally, git fetch
  4. git push -d origin bran... and press Tab.

Versions

  • Prezto commit: 5d7c990
  • ZSH version: zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
  • OS information: Ubuntu 18.04 x64

nyanpasu64 avatar Mar 11 '19 06:03 nyanpasu64

@nyanpasu64: Is it still the case, I do not observe the same behaviour. Could you give information about you shell and git?

srijanshetty avatar May 24 '20 15:05 srijanshetty

Yup, that happen to me too.

Try it with prezto repo.

git clone https://github.com/sorin-ionescu/prezto.git
cd prezto
git push -d origin bel<TAB>

latest prezto, git v2.27.0.rc0

diraol avatar May 24 '20 18:05 diraol

I have since switched to fish, which seems to have the exact same bug in its default configuration (not 100% sure though).

nyanpasu64 avatar May 24 '20 20:05 nyanpasu64

@diraol did try it out and the bel<TAB> expands to origin/bel..., but isn't that the expected behaviour? There's no local branch starting with the prefix bel, so the completion system tries to complete to a remote ref of origin/bel...

srijanshetty avatar May 25 '20 06:05 srijanshetty

The proper syntax to delete origin/branch (both locally and on the origin remote) is git push -d origin branch, not origin/branch.

nyanpasu64 avatar May 25 '20 10:05 nyanpasu64

@nyanpasu64 not contesting the syntax of deletion. I'm contesting the semantics of the completion engine which has to figure out the completion. After typing origin, it needs a local branch which does not exist. When you type bel<TAB> it can only complete to a remote HEAD as no local HEAD exists with that prefix. This is how completion on TAB looks without a prefix:

Screenshot from 2020-05-25 17-46-58

This seems like the correct behaviour to me, but I can be wrong.

srijanshetty avatar May 25 '20 12:05 srijanshetty

it should only suggest remote branches existing on origin, but omit the origin/ prefix.

(sorry for double post via FastHub app)

nyanpasu64 avatar May 25 '20 21:05 nyanpasu64