completion: add test showing subpar git switch completion
commitfab466f91dca22f8ed43148bcde6aac856c5c671
authorJacob Keller <jacob.keller@gmail.com>
Thu, 28 May 2020 18:10:33 +0000 (28 11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 May 2020 19:53:24 +0000 (28 12:53 -0700)
tree597f8a8fe0f37385f3bf4d791c49fb44112a84b4
parente870325ee8575d5c3d7afe0ba2c9be072c692b65
completion: add test showing subpar git switch completion

When provided with no options, git switch only allows switching between
branches. The one exception to this is the "Do What I Mean" logic that
allows a unique remote branch name to be interpreted as a request to
create a branch of the same name that is tracking that remote branch.

Unfortunately, the logic for the completion of git switch results in
completing not just branch names, but also pseudorefs like HEAD, tags,
and fully specified <remote>/<branch> references.

For example, we currently complete the following:

 $git switch <TAB>
 HEAD
 branch-in-other
 master
 master-in-other
 matching-branch
 matching-tag
 other/branch-in-other
 other/master-in-other

Indeed, if one were to attempt to use git switch with some of these
provided options, git will reject the request:

 $git switch HEAD
 fatal: a branch is expected, got 'HEAD

 $git switch matching-tag
 fatal: a branch is expected, got tag 'matching-tag'

 $git switch other/branch-in-other
 fatal: a branch is expected, got remote branch 'other/branch-in-other'

Ideally, git switch without options ought to complete only words which
will be accepted. Without options, this means to list local branch names
and the unique remote branch names without their remote name pre-pended.

 $git switch <TAB>
 branch-in-other
 master
 master-in-other
 matching-branch

Add a test case that highlights this subpar completion. Also add
a similar test for git checkout completion that shows that due to the
complex nature of git checkout, it must complete all references.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9902-completion.sh