Skip to content

Commit af8910a

Browse files
bkeringitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1f74dd commit af8910a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,20 @@ _git_bisect ()
14491449
{
14501450
__git_has_doubledash && return
14511451

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"
14531466
local subcommand="$(__git_find_on_cmdline "$subcommands")"
14541467
if [ -z "$subcommand" ]; then
14551468
__git_find_repo_path
@@ -1462,7 +1475,22 @@ _git_bisect ()
14621475
fi
14631476

14641477
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)
14661494
__git_complete_refs
14671495
;;
14681496
*)

t/t9902-completion.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,12 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
13211321
test_completion "git bisect " <<-\EOF
13221322
start Z
13231323
bad Z
1324+
custom_new Z
1325+
custom_old Z
13241326
new Z
13251327
good Z
13261328
old Z
1329+
terms Z
13271330
skip Z
13281331
reset Z
13291332
visualize Z
@@ -1335,6 +1338,18 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
13351338
)
13361339
'
13371340

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+
13381353
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
13391354
test_completion "git checkout " <<-\EOF
13401355
HEAD Z

0 commit comments

Comments
 (0)