completion(switch/checkout): treat --track and -t the same
When `git switch --track ` is to be completed, only remote refs are eligible because that is what the `--track` option targets. And when the short-hand `-t` is used instead, the same _should_ happen. Let's make it so. Note that the bug exists both in the completions of `switch` and `completion`, even if it manifests in slightly different ways: While the completion of `git switch -t ` will not even look at remote refs, the completion of `git checkout -t ` will look at both remote _and_ local refs. Both should look only at remote refs. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Sep 8, 2023 at 12:28 UTC
9f892830d6965d68bfa937cebcfbed9c9e552700
2 files changed
+12
-4
contrib/completion/git-completion.bash
+2
-2
@@ -1607,7 +1607,7 @@ _git_checkout ()
1607
1608
if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1609
__git_complete_refs --mode="refs"
1610
- elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
1610
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
1611
__git_complete_refs --mode="remote-heads"
1612
else
1613
__git_complete_refs $dwim_opt --mode="refs"
@@ -2484,7 +2484,7 @@ _git_switch ()
2484
2485
if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2486
__git_complete_refs --mode="refs"
2487
- elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
2487
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
2488
__git_complete_refs --mode="remote-heads"
2489
else
2490
__git_complete_refs $dwim_opt --mode="heads"
t/t9902-completion.sh
+10
-2
@@ -1622,14 +1622,22 @@ test_expect_success 'git checkout - with -d, complete only references' '
1622
'
1623
1624
test_expect_success 'git switch - with --track, complete only remote branches' '
1625
- test_completion "git switch --track " <<-\EOF
1625
+ test_completion "git switch --track " <<-\EOF &&
1626
+ other/branch-in-other Z
1627
+ other/main-in-other Z
1628
+ EOF
1629
+ test_completion "git switch -t " <<-\EOF
1630
other/branch-in-other Z
1631
other/main-in-other Z
1632
EOF
1633
'
1634
1635
test_expect_success 'git checkout - with --track, complete only remote branches' '
1632
- test_completion "git checkout --track " <<-\EOF
1636
+ test_completion "git checkout --track " <<-\EOF &&
1637
+ other/branch-in-other Z
1638
+ other/main-in-other Z
1639
+ EOF
1640
+ test_completion "git checkout -t " <<-\EOF
1641
other/branch-in-other Z
1642
other/main-in-other Z
1643
EOF