@@ -1489,7 +1489,12 @@ _git_checkout ()
;;
*)
local dwim_opt="$(__git_checkout_default_dwim_mode)"
- __git_complete_refs $dwim_opt
+
+ if [ -n "$(__git_find_on_cmdline "-d --detach")" ]; then
+ __git_complete_refs --mode="refs"
+ else
+ __git_complete_refs $dwim_opt --mode="refs"
+ fi
;;
esac
}
@@ -1360,6 +1360,50 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues
EOF
'
+test_expect_success 'git switch - with --detach, complete all references' '
+ test_completion "git switch --detach " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git checkout - with --detach, complete only references' '
+ test_completion "git checkout --detach " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git switch - with -d, complete all references' '
+ test_completion "git switch -d " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git checkout - with -d, complete only references' '
+ test_completion "git checkout -d " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
test_expect_success 'teardown after ref completion' '
git branch -d matching-branch &&
git tag -d matching-tag &&