Skip to content

refactor completion for switch and checkout

Jacob Keller git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest9 patches 3 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9completion: replace overloaded track term for __git_complete_refscontrib/completion/git-completion.bash+15 -130 replies
2/9completion: improve handling of DWIM mode for switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+174 -193 replies
3/9completion: extract function __git_dwim_remote_headscontrib/completion/git-completion.bash+21 -70 replies
4/9completion: perform DWIM logic directly in __git_complete_refscontrib/completion/git-completion.bash+18 -10 replies
5/9completion: improve completion for git switch with no optionscontrib/completion/git-completion.bash t/t9902-completion.sh+44 -150 replies
6/9completion: improve handling of --detach in checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+50 -10 replies
7/9completion: improve handling of --track in switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+54 -20 replies
8/9completion: improve handling of -c/-C and -b/-B in switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+271 -20 replies
9/9completion: improve handling of --orphan option of switch/checkoutcontrib/completion/git-completion.bash t/t9902-completion.sh+49 -70 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 0/9] refactor completion for switch and checkout

From: Jacob Keller <[email protected]>

completion support for git switch is subpar for a number of cases. Most notable is difference in behavior between these two completions:

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

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

If --track is provided, tab completion becomes almost useless, because we would expect to complete remote references, but instead can only complete local branches!

This series was motivated by a desire to fix the completion for the above two cases, but I noticed several other issues on the way, including some issues understanding what the current logic did.

This series aims to improve the completion support, and comes with many additional test cases that cover the new behavior implemented in the various patches.

This is a rework of a previous series posted, available at the following URL:
https://lore.kernel.org/git/[email protected]/

Note that although I've marked this as a v2, I did not find the range-diff to be satisfying or useful and have not included it. Besides not being very useful, not many folks seem to have reviewed the original anyways.

The most notable change in behavior since v1 is how we handle the -c/-C options. It makes sense to complete the argument of -c differently than how we handle the start-point after we already have a completed branch name. The exact requirements of *how* we complete branch names is easily modified if anyone has a better suggestion.

Finally, I also applied many of the same improvements to checkout where appropriate, and have included many more additional tests for both git switch and git checkout.

Jacob Keller (9):
completion: replace overloaded track term for __git_complete_refs
completion: improve handling of DWIM mode for switch/checkout
completion: extract function __git_dwim_remote_heads
completion: perform DWIM logic directly in __git_complete_refs
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                  | 455 +++++++++++++++++++++++++
 2 files changed, 668 insertions(+), 39 deletions(-)
Signature · 1 line
2.25.2