Skip to content

Commit d8e08f0

Browse files
bkeringitster
authored andcommitted
completion: bisect: recognize but do not complete view subcommand
The "view" alias for the visualize subcommand is neither completed nor recognized. It's undesirable to complete it because it's first letters are the same as for visualize, making completion less rather than more efficient without adding much in the way of interface discovery. However, it needs to be recognized in order to enable log option completion for it. Recognize but do not complete the view command by creating and using separate lists of completable_subcommands and all_subcommands. Add tests. Signed-off-by: Britton Leo Kerin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d115b87 commit d8e08f0

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,12 +1462,19 @@ _git_bisect ()
14621462
# more usual bad/new/good/old because git bisect gives a good error
14631463
# message if these are given when not in use, and that's better than
14641464
# silent refusal to complete if the user is confused.
1465-
local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
1466-
local subcommand="$(__git_find_on_cmdline "$subcommands")"
1465+
#
1466+
# We want to recognize 'view' but not complete it, because it overlaps
1467+
# with 'visualize' too much and is just an alias for it.
1468+
#
1469+
local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
1470+
local all_subcommands="$completable_subcommands view"
1471+
1472+
local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
1473+
14671474
if [ -z "$subcommand" ]; then
14681475
__git_find_repo_path
14691476
if [ -f "$__git_repo_path"/BISECT_START ]; then
1470-
__gitcomp "$subcommands"
1477+
__gitcomp "$completable_subcommands"
14711478
else
14721479
__gitcomp "replay start"
14731480
fi
@@ -1490,7 +1497,7 @@ _git_bisect ()
14901497
__gitcomp "--term-good --term-old --term-bad --term-new"
14911498
return
14921499
;;
1493-
visualize)
1500+
visualize|view)
14941501
__git_complete_log_opts
14951502
return
14961503
;;

t/t9902-completion.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,30 @@ test_expect_success 'git-bisect - git-log options to visualize subcommand are ca
13761376
)
13771377
'
13781378

1379+
test_expect_success 'git-bisect - view subcommand is not a candidate' '
1380+
(
1381+
cd git-bisect &&
1382+
test_completion "git bisect vi" <<-\EOF
1383+
visualize Z
1384+
EOF
1385+
)
1386+
'
1387+
1388+
test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
1389+
(
1390+
cd git-bisect &&
1391+
# The completion used for git-log and here does not complete
1392+
# every git-log option, so rather than hope to stay in sync
1393+
# with exactly what it does we will just spot-test here.
1394+
test_completion "git bisect view --sta" <<-\EOF &&
1395+
--stat Z
1396+
EOF
1397+
test_completion "git bisect view --summar" <<-\EOF
1398+
--summary Z
1399+
EOF
1400+
)
1401+
'
1402+
13791403
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
13801404
test_completion "git checkout " <<-\EOF
13811405
HEAD Z

0 commit comments

Comments
 (0)