Skip to content

Commit 6d76a5c

Browse files
jacob-kellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68d97c7 commit 6d76a5c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,12 @@ _git_checkout ()
14891489
;;
14901490
*)
14911491
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
14931498
;;
14941499
esac
14951500
}

t/t9902-completion.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,7 @@ test_expect_success 'git switch - with --detach, complete all references' '
13711371
EOF
13721372
'
13731373

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' '
13761375
test_completion "git checkout --detach " <<-\EOF
13771376
HEAD Z
13781377
master Z
@@ -1394,8 +1393,7 @@ test_expect_success 'git switch - with -d, complete all references' '
13941393
EOF
13951394
'
13961395

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' '
13991397
test_completion "git checkout -d " <<-\EOF
14001398
HEAD Z
14011399
master Z

0 commit comments

Comments
 (0)