completion: bisect: complete custom terms and related options

git bisect supports the use of custom terms via the --term-(new|bad) and --term-(old|good) options, but the completion code doesn't know about these options or the new subcommands they define. Add support for these options and the custom subcommands by checking for BISECT_TERMS and adding them to the list of 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 af8910a2d4cdc3452c4b48e073e18fc10ff76723
2 files changed +45 -2
contrib/completion/git-completion.bash
+30 -2
@@ -1449,7 +1449,20 @@ _git_bisect ()
1449 {
1450 __git_has_doubledash && return
1451
1452 - local subcommands="start bad new good old skip reset visualize replay log run help"
1452 + __git_find_repo_path
1453 +
1454 + # If a bisection is in progress get the terms being used.
1455 + local term_bad term_good
1456 + if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
1457 + term_bad=$(__git bisect terms --term-bad)
1458 + term_good=$(__git bisect terms --term-good)
1459 + fi
1460 +
1461 + # We will complete any custom terms, but still always complete the
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")"
1467 if [ -z "$subcommand" ]; then
1468 __git_find_repo_path
@@ -1462,7 +1475,22 @@ _git_bisect ()
1475 fi
1476
1477 case "$subcommand" in
1465 - bad|new|good|old|reset|skip|start)
1478 + start)
1479 + case "$cur" in
1480 + --*)
1481 + __gitcomp "--term-new --term-bad --term-old --term-good"
1482 + return
1483 + ;;
1484 + *)
1485 + __git_complete_refs
1486 + ;;
1487 + esac
1488 + ;;
1489 + terms)
1490 + __gitcomp "--term-good --term-old --term-bad --term-new"
1491 + return
1492 + ;;
1493 + bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
1494 __git_complete_refs
1495 ;;
1496 *)
t/t9902-completion.sh
+15
@@ -1321,9 +1321,12 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
1321 test_completion "git bisect " <<-\EOF
1322 start Z
1323 bad Z
1324 + custom_new Z
1325 + custom_old Z
1326 new Z
1327 good Z
1328 old Z
1329 + terms Z
1330 skip Z
1331 reset Z
1332 visualize Z
@@ -1335,6 +1338,18 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
1338 )
1339 '
1340
1341 +test_expect_success 'git-bisect - options to terms subcommand are candidates' '
1342 + (
1343 + cd git-bisect &&
1344 + test_completion "git bisect terms --" <<-\EOF
1345 + --term-bad Z
1346 + --term-good Z
1347 + --term-new Z
1348 + --term-old Z
1349 + EOF
1350 + )
1351 +'
1352 +
1353 test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
1354 test_completion "git checkout " <<-\EOF
1355 HEAD Z