From 6d76a5cc7fd19989b32a3b6d4a6132a7dd6aee4e Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Thu, 28 May 2020 11:10:45 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 19d08828b6..56480371ff 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -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 } -- cgit v1.2.3