8

I've updated git to its latest version (2.29.0) and I'm using ZSH 5.8.

I used to switch between branches with git checkout remote_br<tab> to quickly switch between branches, even if the branch is only a remote one atm. I've seen git has made a lot of changes regarding switch/checkout recently, the thing is my autocompletion on remote branches doesn't work anymore (with checkout or switch).

I've tried to add the latest version of contrib/completion/git-completion.zsh to my zsh, but I still have my issue. Am I missing something here ?

RobinFrcd
  • 4,439
  • 4
  • 25
  • 49
  • As you've seen, there has been a mini-flurry of activity on the completion scripts, to account for the `switch` command and so on. I recall there was a change or two to make DWIM completion optional as well. It sounds like it's turned off in yours. I don't actually use this feature and I don't remember what the enable/disable settings are. – torek Sep 07 '20 at 21:08
  • Note that when you've run `git fetch` and picked up a new remote-tracking name such as `origin/xyz-feature`, you don't actually have a (local) branch name `xyz-feature` at all. The switch or checkout command will *create* your `xyz-feature` from `origin/xyz-feature` on demand, and Git refers to this as "checkout DWIM" (Do What I Mean). – torek Sep 07 '20 at 21:09
  • The reason for making this optional is that some repositories have hundreds of similarly-named branches, so that if you *do* use completion, and have one local branch named `sanity` for instance, but your upstream has 78 branches whose names all start with `s`, you can't just type `s`. Turning off DWIM-style completion, you *can* just type `s`. But in your case, you want it turned *on*. That might be a useful hint in looking through the completion scripts, anyway. – torek Sep 07 '20 at 21:11
  • I've read trough all recent change logs, I don't see anything. When looking at the commits I think it may be related to something like: https://github.com/git/git/commit/68d97c7fdd5bbfd87b2e0b14ddfcd2b1825b2059 but I don't see the issue. I've checked `__git_checkout_default_dwim_mode` which returns `--dwim` as expected. – RobinFrcd Sep 08 '20 at 00:14
  • Any solution for the issue? I did a downgrade to 2.27.0, but that's not satisfying. – Helden Oct 04 '20 at 11:18
  • Nope, still stuck, had to downgrade too. – RobinFrcd Oct 04 '20 at 12:09
  • 1
    as of git version 2.30.0 (released 2020-12-27), this seems to have been fixed. I have updated and it is working properly for me in zsh. – rocksteady Dec 30 '20 at 18:33

2 Answers2

3

I've been looking into this for the last few hours and have identified the regression.

The regression occurs in 6880779.

To temporarily resolve this: replace your git-completion.bash file (mine's located at /usr/local/share/zsh/site-functions/git-completion.bash) with https://github.com/git/git/blob/688077910bdfbd502cb59c9c48a2af2c97d8b67b~1/contrib/completion/git-completion.bash

To really resolve this, upvote my git PR and help get it merged! (https://github.com/git/git/pull/902)

Max Coplan
  • 1,111
  • 13
  • 27
  • Same as @FelipeC, it works on local branches but not on remote ones. As long as the branch has not been fetched, the auto-completion doesn't work for me :/ – RobinFrcd Oct 26 '20 at 09:58
  • The version I posted here works for remote branches – Max Coplan Oct 26 '20 at 15:51
  • Or better yet: Just use Zsh's built-in Git completion. It's way better than the one that ships with Git. – Marlon Richert Oct 27 '20 at 09:04
  • 1
    This patch already has been sent to the ML and it's already queued. No need to send a PR. https://lore.kernel.org/git/20201028020712.442623-14-felipe.contreras@gmail.com/ – FelipeC Nov 05 '20 at 00:49
2

Try the following patch:

--- a/git-completion.zsh
+++ b/git-completion.zsh
@@ -97,6 +97,11 @@ __gitcomp_direct ()
        compadd -Q -S '' -- ${(f)1} && _ret=0
 }
 
+__gitcomp_direct_append ()
+{
+       __gitcomp_direct "$@"
+}
+
 __gitcomp_nl ()
 {
        emulate -L zsh

In general it's better to report bugs to the git mailing list, however, I'm the maintainer of the zsh code, which is more up to date in my fork: git-completion.

FelipeC
  • 9,123
  • 4
  • 44
  • 38
  • It works on local branches but not on remote ones. As long as the branch has not been fetched, the auto-completion doesn't work. (Tested with your current master: https://github.com/felipec/git-completion/blob/282bb9bc13b926f5e6fbbc0966570220a63f37ad/git-completion.bash) – RobinFrcd Oct 26 '20 at 09:54
  • @FelipeC Should I direct my [PR](https://github.com/git/git/pull/902) to you? – Max Coplan Oct 26 '20 at 16:08
  • BTW your suggestion is very similar to what [I did](https://github.com/git/git/pull/902/files#diff-ac06d8a41d816b7182a4755e4258784c81b9b151bb5f6eabb32bc6465b419486R834) – Max Coplan Oct 26 '20 at 16:08
  • @RobinFrcd It should work on both. Exactly as it does in Bash. Do you have a test case where it doesn't? – FelipeC Nov 05 '20 at 00:53
  • 1
    Forgot to edit my comment, everything works as expected now, thanks! – RobinFrcd Nov 05 '20 at 01:00