Skip to content

Commit

Permalink
Merge branch 'js/complete-checkout-t' into next
Browse files Browse the repository at this point in the history
The completion script (in contrib/) has been taught to treat the
"-t" option to "git checkout" and "git switch" just like the
"--track" option, to complete remote-tracking branches.

* js/complete-checkout-t:
  completion(switch/checkout): treat --track and -t the same
  • Loading branch information
gitster committed Sep 8, 2023
2 parents 8425870 + 9f89283 commit 461bb28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ _git_checkout ()

if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
__git_complete_refs --mode="refs"
elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
__git_complete_refs --mode="remote-heads"
else
__git_complete_refs $dwim_opt --mode="refs"
Expand Down Expand Up @@ -2523,7 +2523,7 @@ _git_switch ()

if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
__git_complete_refs --mode="refs"
elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
__git_complete_refs --mode="remote-heads"
else
__git_complete_refs $dwim_opt --mode="heads"
Expand Down
12 changes: 10 additions & 2 deletions t/t9902-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1622,14 +1622,22 @@ test_expect_success 'git checkout - with -d, complete only references' '
'

test_expect_success 'git switch - with --track, complete only remote branches' '
test_completion "git switch --track " <<-\EOF
test_completion "git switch --track " <<-\EOF &&
other/branch-in-other Z
other/main-in-other Z
EOF
test_completion "git switch -t " <<-\EOF
other/branch-in-other Z
other/main-in-other Z
EOF
'

test_expect_success 'git checkout - with --track, complete only remote branches' '
test_completion "git checkout --track " <<-\EOF
test_completion "git checkout --track " <<-\EOF &&
other/branch-in-other Z
other/main-in-other Z
EOF
test_completion "git checkout -t " <<-\EOF
other/branch-in-other Z
other/main-in-other Z
EOF
Expand Down

0 comments on commit 461bb28

Please sign in to comment.