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 <britton.kerin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Britton Leo Kerin committed
Feb 6, 2024 at 12:50 UTC
d8e08f0717c17b2ee629c50844c34adc83575ad0
2 files changed
+35
-4
contrib/completion/git-completion.bash
+11
-4
@@ -1462,12 +1462,19 @@ _git_bisect ()
1462
# more usual bad/new/good/old because git bisect gives a good error
1463
# message if these are given when not in use, and that's better than
1464
# 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
+
1474
if [ -z "$subcommand" ]; then
1475
__git_find_repo_path
1476
if [ -f "$__git_repo_path"/BISECT_START ]; then
1470
- __gitcomp "$subcommands"
1477
+ __gitcomp "$completable_subcommands"
1478
else
1479
__gitcomp "replay start"
1480
fi
@@ -1490,7 +1497,7 @@ _git_bisect ()
1497
__gitcomp "--term-good --term-old --term-bad --term-new"
1498
return
1499
;;
1493
- visualize)
1500
+ visualize|view)
1501
__git_complete_log_opts
1502
return
1503
;;
t/t9902-completion.sh
+24
@@ -1376,6 +1376,30 @@ test_expect_success 'git-bisect - git-log options to visualize subcommand are ca
1376
)
1377
'
1378
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
+
1403
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1404
test_completion "git checkout " <<-\EOF
1405
HEAD Z