]> git.ipfire.org Git - thirdparty/git.git/commit - contrib/completion/git-completion.bash
completion: improve handling of -c/-C and -b/-B in switch/checkout
authorJacob Keller <jacob.keller@gmail.com>
Thu, 28 May 2020 18:10:47 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 May 2020 19:57:07 +0000 (12:57 -0700)
commitacb658fe7d6bc11136be0756270fda675af74761
treee8e5cd9c27796e74b5c83b60d24d6d4ff63021dd
parent00e7bd2b0057a20d78193405af73b0acebdd86d2
completion: improve handling of -c/-C and -b/-B in switch/checkout

A previous commit added several test cases highlighting the subpar
completion logic for -c/-C and -b/-B when completing git switch and git
checkout.

In order to distinguish completing the argument vs the start-point for
this option, we now use the wordlist to determine the previous full word
on the command line.

If it's -c or -C (-b/-B for checkout), then we know that we are
completing the argument for the branch name.

Given that a user who already knows the branch name they want to
complete will simply not use completion, it makes sense to complete the
small subset of local branches when completing the argument for -c/-C.

In all other cases, if -c/-C are on the command line but are not the
most recent option, then we must be completing a start-point, and should
allow completing against all references.

Update the -c/-C and -b/-B tests to indicate they now pass.

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