[v3,00/16] improve switch/checkout completion
mbox series

Message ID 20200528181048.3509470-1-jacob.e.keller@intel.com
Headers show
Series
  • improve switch/checkout completion
Related show

Message

Jacob Keller May 28, 2020, 6:10 p.m. UTC
From: Jacob Keller <jacob.keller@gmail.com>

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/20200422201541.3766173-1-jacob.e.keller@intel.com/

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/20200425022045.1089291-1-jacob.e.keller@intel.com/

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/20200527113831.3294409-1-jacob.e.keller@intel.com/

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(-)