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>
@ -1436,8 +1436,7 @@ test_expect_success 'git checkout - with --no-track, complete only local referen
@@ -1436,8 +1436,7 @@ test_expect_success 'git checkout - with --no-track, complete only local referen
EOF
'
#TODO: completing the start point of -c/-C should not include DWIM references
test_expect_failure 'git switch - with -c, complete all references' '
test_expect_success 'git switch - with -c, complete all references' '
@ -1472,8 +1469,7 @@ test_expect_failure 'git switch - with -c and --track, complete all references'
@@ -1472,8 +1469,7 @@ test_expect_failure 'git switch - with -c and --track, complete all references'
EOF
'
#TODO: completing the start point of -c/-C should include all references, not just local branches
test_expect_failure 'git switch - with -C and --track, complete all references' '
test_expect_success 'git switch - with -C and --track, complete all references' '
@ -1484,8 +1480,7 @@ test_expect_failure 'git switch - with -C and --track, complete all references'
@@ -1484,8 +1480,7 @@ test_expect_failure 'git switch - with -C and --track, complete all references'
EOF
'
#TODO: completing the start point of -c/-C should include all references, not just local branches
test_expect_failure 'git switch - with -c and --no-track, complete all references' '
test_expect_success 'git switch - with -c and --no-track, complete all references' '
@ -1496,8 +1491,7 @@ test_expect_failure 'git switch - with -c and --no-track, complete all reference
@@ -1496,8 +1491,7 @@ test_expect_failure 'git switch - with -c and --no-track, complete all reference
EOF
'
#TODO: completing the start point of -c/-C should include all references, not just local branches
test_expect_failure 'git switch - with -C and --no-track, complete all references' '
test_expect_success 'git switch - with -C and --no-track, complete all references' '
@ -1508,8 +1502,7 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference
@@ -1508,8 +1502,7 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference
EOF
'
#TODO: completing the start point of -b/-B should not include DWIM references
test_expect_failure 'git checkout - with -b, complete all references' '
test_expect_success 'git checkout - with -b, complete all references' '
@ -1544,8 +1535,7 @@ test_expect_failure 'git checkout - with -b and --track, complete all references
@@ -1544,8 +1535,7 @@ test_expect_failure 'git checkout - with -b and --track, complete all references
EOF
'
#TODO: completing the start point of -b/-B should not include DWIM references
test_expect_failure 'git checkout - with -B and --track, complete all references' '
test_expect_success 'git checkout - with -B and --track, complete all references' '
@ -1624,8 +1614,7 @@ test_expect_success 'git switch - for -C with --no-track, complete local branche
@@ -1624,8 +1614,7 @@ test_expect_success 'git switch - for -C with --no-track, complete local branche
EOF
'
#TODO: -b/-B argument completion should not include all references
test_expect_failure 'git checkout - for -b, complete local branches and unique remote branches' '
test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
test_completion "git checkout -b " <<-\EOF
branch-in-other Z
master Z
@ -1634,8 +1623,7 @@ test_expect_failure 'git checkout - for -b, complete local branches and unique r
@@ -1634,8 +1623,7 @@ test_expect_failure 'git checkout - for -b, complete local branches and unique r
EOF
'
#TODO: -b/-B argument completion should not include all references
test_expect_failure 'git checkout - for -B, complete local branches and unique remote branches' '
test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
test_completion "git checkout -B " <<-\EOF
branch-in-other Z
master Z
@ -1644,32 +1632,28 @@ test_expect_failure 'git checkout - for -B, complete local branches and unique r
@@ -1644,32 +1632,28 @@ test_expect_failure 'git checkout - for -B, complete local branches and unique r
EOF
'
#TODO: -b/-B argument completion should not include all references
test_expect_failure 'git checkout - for -b with --no-guess, complete local branches only' '
test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '