Skip to content

improve switch/checkout completion

Jacob Keller git 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest16 patches 0 repliesNew

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16completion: add test showing subpar git switch completiont/t9902-completion.sh+23 -00 replies
2/16completion: add tests showing subpar DWIM logic for switch/checkoutt/t9902-completion.sh+105 -00 replies
3/16completion: add tests showing subar checkout --detach logict/t9902-completion.sh+46 -00 replies
4/16completion: add tests showing subpar switch/checkout --track logict/t9902-completion.sh+34 -00 replies
5/16completion: add tests showing subpar -c/-C startpoint completiont/t9902-completion.sh+140 -00 replies
6/16completion: add tests showing subpar -c/C argument completiont/t9902-completion.sh+100 -00 replies
7/16completion: add tests showing subpar switch/checkout --orphan logict/t9902-completion.sh+39 -00 replies
8/16completion: replace overloaded track term for __git_complete_refscontrib/completion/git-completion.bash+15 -130 replies
9/16completion: extract function __git_dwim_remote_headscontrib/completion/git-completion.bash+21 -70 replies
10/16completion: perform DWIM logic directly in __git_complete_refscontrib/completion/git-completion.bash+18 -10 replies
11/16completion: improve handling of DWIM mode for switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+83 -290 replies
12/16completion: improve completion for git switch with no optionscontrib/completion/git-completion.bash t/t9902-completion.sh+27 -250 replies
13/16completion: improve handling of --detach in checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+8 -50 replies
14/16completion: improve handling of --track in switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+24 -60 replies
15/16completion: improve handling of -c/-C and -b/-B in switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+63 -340 replies
16/16completion: improve handling of --orphan option of switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+17 -130 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 00/16] improve switch/checkout completion

From: Jacob Keller <[email protected]>

Recently I noticed that the completion support for git switch is subpar, and can lead to frustrating moments. Specifically the difference between completing git switch vs git switch --track:

$git switch <TAB>
Display all 784 possibilities? (y or n)
<list of all references and DWIM remotes>

Notice that git switch will complete basically all references, including things like HEAD, and remote references like "origin/master". Many of these values are useless and clutter the output. It's not too bad, but could be somewhat improved. At least it still completes useful words.

However, the same cannot be said for --track:

  $git switch --track<TAB>
  jk-refactor-git-switch-completion master

Notice that with --track, we suddenly start completing only local branches. Not only does this severely limit what we complete, it includes *only* useless words. This leads to incredibly frustrating moments, as I often use "git switch --track remote/<TAB>" to create tracking branches. I found myself often having to backspace --track just to complete what I wanted and then re-add it.

The primary original motivation of this series was to improve the handling of track. Several other issues were discovered, and I attempt to improve pretty much every mode of switch.

The first few patches simply add new test cases, most of which fail. This is done in order to give time to fully explain what I believe is deficient about the specific case.

Following these patches are some cleanup improvements to remove some confusing terminology and introduce new functions that will be useful to improve the completion functions.

Finally, several patches which improve completion follow. By the end, completion for both git switch and git checkout should be more useful and more aware of the intention of the current argument being completed.

A patch to initially fix just the --track behavior was posted at
https://lore.kernel.org/git/[email protected]/

This original patch was reviewed by Jonathan Nieder, and he suggested further improvements, which led to v1 of this series
https://lore.kernel.org/git/[email protected]/

This was further reviewed, and some issues with the handling of completing the argument to -c/-C were brought up by Junio, which I then improved in v2
https://lore.kernel.org/git/[email protected]/

Junio mentioned that the commit messages for this v2 series were difficult to follow. I have split the tests from the implementation patches and re-written the commit messages. Hopefully this now better highlights the places where completion isn't behaving as I would expect.

Once again, given the nature of the rework I did not find a suitable range-diff that expressed the evolution from v2 to v3, so I haven't included it here.

I would really like opinions on whether the suggested -c/-C argument completion makes sense. I opted to limit it to complete local branch names, and optionally the unique remote branch names. I'm open to alternative suggestions if anyone has a better suggestion? I had thought perhaps also some users might wish to see tags, if they have branches named after tags or similar.. I don't think completing all references makes sense: branches with remote prefixes in their name would be confusing.

Jacob Keller (16):
completion: add test showing subpar git switch completion
completion: add tests showing subpar DWIM logic for switch/checkout
completion: add tests showing subar checkout --detach logic
completion: add tests showing subpar switch/checkout --track logic
completion: add tests showing subpar -c/-C startpoint completion
completion: add tests showing subpar -c/C argument completion
completion: add tests showing subpar switch/checkout --orphan logic
completion: replace overloaded track term for __git_complete_refs
completion: extract function __git_dwim_remote_heads
completion: perform DWIM logic directly in __git_complete_refs
completion: improve handling of DWIM mode for switch/checkout
completion: improve completion for git switch with no options
completion: improve handling of --detach in checkout
completion: improve handling of --track in switch/checkout
completion: improve handling of -c/-C and -b/-B in switch/checkout
completion: improve handling of --orphan option of switch/checkout

 contrib/completion/git-completion.bash | 252 +++++++++++---
 t/t9902-completion.sh                  | 456 +++++++++++++++++++++++++
 2 files changed, 669 insertions(+), 39 deletions(-)
Signature · 1 line
2.25.2