completion: improve handling of --detach in checkout
Just like git switch, we should not complete DWIM remote branch names if --detach has been specified. To avoid this, refactor _git_checkout in a similar way to _git_switch. Note that we don't simply clear dwim_opt when we find -d or --detach, as we will be adding other modes and checks, making this flow easier to follow. Update the previously failing tests to show that the breakage has been resolved. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
May 28, 2020 at 11:10 UTC
6d76a5cc7fd19989b32a3b6d4a6132a7dd6aee4e
2 files changed
+8
-5
contrib/completion/git-completion.bash
+6
-1
@@ -1489,7 +1489,12 @@ _git_checkout ()
1489
;;
1490
*)
1491
local dwim_opt="$(__git_checkout_default_dwim_mode)"
1492
- __git_complete_refs $dwim_opt
1492
+
1493
+ if [ -n "$(__git_find_on_cmdline "-d --detach")" ]; then
1494
+ __git_complete_refs --mode="refs"
1495
+ else
1496
+ __git_complete_refs $dwim_opt --mode="refs"
1497
+ fi
1498
;;
1499
esac
1500
}
t/t9902-completion.sh
+2
-4
@@ -1371,8 +1371,7 @@ test_expect_success 'git switch - with --detach, complete all references' '
1371
EOF
1372
'
1373
1374
-#TODO: checkout --detach incorrectly includes DWIM remote branch names
1375
-test_expect_failure 'git checkout - with --detach, complete only references' '
1374
+test_expect_success 'git checkout - with --detach, complete only references' '
1375
test_completion "git checkout --detach " <<-\EOF
1376
HEAD Z
1377
master Z
@@ -1394,8 +1393,7 @@ test_expect_success 'git switch - with -d, complete all references' '
1393
EOF
1394
'
1395
1397
-#TODO: checkout -d incorrectly includes DWIM remote branch names
1398
-test_expect_failure 'git checkout - with -d, complete only references' '
1396
+test_expect_success 'git checkout - with -d, complete only references' '
1397
test_completion "git checkout -d " <<-\EOF
1398
HEAD Z
1399
master Z