git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 28, 2020, 18:10 UTC
Message-ID
<20200528181048.3509470-1-jacob.e.keller@intel.com>
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(-)
-- 
2.25.2
Next: Jacob Keller
Message 1 of 17 in “improve switch/checkout completion”
  1. 00/16 improve switch/checkout completionJacob Keller, May 28, 2020
  2. 10/16 completion: perform DWIM logic directly in __git_complete_refsJacob Keller, May 28, 2020
  3. 08/16 completion: replace overloaded track term for __git_complete_refsJacob Keller, May 28, 2020
  4. 09/16 completion: extract function __git_dwim_remote_headsJacob Keller, May 28, 2020
  5. 14/16 completion: improve handling of --track in switch/checkoutJacob Keller, May 28, 2020
  6. 16/16 completion: improve handling of --orphan option of switch/checkoutJacob Keller, May 28, 2020
  7. 12/16 completion: improve completion for git switch with no optionsJacob Keller, May 28, 2020
  8. 07/16 completion: add tests showing subpar switch/checkout --orphan logicJacob Keller, May 28, 2020
  9. 11/16 completion: improve handling of DWIM mode for switch/checkoutJacob Keller, May 28, 2020
  10. 03/16 completion: add tests showing subar checkout --detach logicJacob Keller, May 28, 2020
  11. 04/16 completion: add tests showing subpar switch/checkout --track logicJacob Keller, May 28, 2020
  12. 02/16 completion: add tests showing subpar DWIM logic for switch/checkoutJacob Keller, May 28, 2020
  13. 01/16 completion: add test showing subpar git switch completionJacob Keller, May 28, 2020
  14. 13/16 completion: improve handling of --detach in checkoutJacob Keller, May 28, 2020
  15. 05/16 completion: add tests showing subpar -c/-C startpoint completionJacob Keller, May 28, 2020
  16. 06/16 completion: add tests showing subpar -c/C argument completionJacob Keller, May 28, 2020
  17. 15/16 completion: improve handling of -c/-C and -b/-B in switch/checkoutJacob Keller, May 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.