Skip to content

Commit 4676137

Browse files
committed
Merge branch 'bk/complete-bisect'
Command line completion support (in contrib/) has been updated for "git bisect". * bk/complete-bisect: completion: bisect: recognize but do not complete view subcommand completion: bisect: complete log opts for visualize subcommand completion: new function __git_complete_log_opts completion: bisect: complete missing --first-parent and - -no-checkout options completion: bisect: complete custom terms and related options completion: bisect: complete bad, new, old, and help subcommands completion: tests: always use 'master' for default initial branch name
2 parents f424d7c + d8e08f0 commit 4676137

File tree

2 files changed

+199
-7
lines changed

2 files changed

+199
-7
lines changed

contrib/completion/git-completion.bash

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,20 +1483,59 @@ _git_bisect ()
14831483
{
14841484
__git_has_doubledash && return
14851485

1486-
local subcommands="start bad good skip reset visualize replay log run"
1487-
local subcommand="$(__git_find_on_cmdline "$subcommands")"
1486+
__git_find_repo_path
1487+
1488+
# If a bisection is in progress get the terms being used.
1489+
local term_bad term_good
1490+
if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
1491+
term_bad=$(__git bisect terms --term-bad)
1492+
term_good=$(__git bisect terms --term-good)
1493+
fi
1494+
1495+
# We will complete any custom terms, but still always complete the
1496+
# more usual bad/new/good/old because git bisect gives a good error
1497+
# message if these are given when not in use, and that's better than
1498+
# silent refusal to complete if the user is confused.
1499+
#
1500+
# We want to recognize 'view' but not complete it, because it overlaps
1501+
# with 'visualize' too much and is just an alias for it.
1502+
#
1503+
local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
1504+
local all_subcommands="$completable_subcommands view"
1505+
1506+
local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
1507+
14881508
if [ -z "$subcommand" ]; then
14891509
__git_find_repo_path
14901510
if [ -f "$__git_repo_path"/BISECT_START ]; then
1491-
__gitcomp "$subcommands"
1511+
__gitcomp "$completable_subcommands"
14921512
else
14931513
__gitcomp "replay start"
14941514
fi
14951515
return
14961516
fi
14971517

14981518
case "$subcommand" in
1499-
bad|good|reset|skip|start)
1519+
start)
1520+
case "$cur" in
1521+
--*)
1522+
__gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
1523+
return
1524+
;;
1525+
*)
1526+
__git_complete_refs
1527+
;;
1528+
esac
1529+
;;
1530+
terms)
1531+
__gitcomp "--term-good --term-old --term-bad --term-new"
1532+
return
1533+
;;
1534+
visualize|view)
1535+
__git_complete_log_opts
1536+
return
1537+
;;
1538+
bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
15001539
__git_complete_refs
15011540
;;
15021541
*)
@@ -2105,10 +2144,12 @@ __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-c
21052144
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
21062145
__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
21072146

2108-
_git_log ()
2147+
# Complete porcelain (i.e. not git-rev-list) options and at least some
2148+
# option arguments accepted by git-log. Note that this same set of options
2149+
# are also accepted by some other git commands besides git-log.
2150+
__git_complete_log_opts ()
21092151
{
2110-
__git_has_doubledash && return
2111-
__git_find_repo_path
2152+
COMPREPLY=()
21122153

21132154
local merge=""
21142155
if __git_pseudoref_exists MERGE_HEAD; then
@@ -2204,6 +2245,16 @@ _git_log ()
22042245
return
22052246
;;
22062247
esac
2248+
}
2249+
2250+
_git_log ()
2251+
{
2252+
__git_has_doubledash && return
2253+
__git_find_repo_path
2254+
2255+
__git_complete_log_opts
2256+
[ ${#COMPREPLY[@]} -eq 0 ] || return
2257+
22072258
__git_complete_revlist
22082259
}
22092260

t/t9902-completion.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ test_description='test bash completion'
1111
# untraceable with such ancient Bash versions.
1212
test_untraceable=UnfortunatelyYes
1313

14+
# Override environment and always use master for the default initial branch
15+
# name for these tests, so that rev completion candidates are as expected.
16+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
17+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18+
1419
. ./lib-bash.sh
1520

1621
complete ()
@@ -1267,6 +1272,142 @@ test_expect_success 'git switch - with no options, complete local branches and u
12671272
EOF
12681273
'
12691274

1275+
test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
1276+
test_completion "git bisect " <<-\EOF
1277+
replay Z
1278+
start Z
1279+
EOF
1280+
'
1281+
1282+
test_expect_success 'git bisect - complete options to start subcommand' '
1283+
test_completion "git bisect start --" <<-\EOF
1284+
--term-new Z
1285+
--term-bad Z
1286+
--term-old Z
1287+
--term-good Z
1288+
--no-checkout Z
1289+
--first-parent Z
1290+
EOF
1291+
'
1292+
1293+
test_expect_success 'setup for git-bisect tests requiring a repo' '
1294+
git init git-bisect &&
1295+
(
1296+
cd git-bisect &&
1297+
echo "initial contents" >file &&
1298+
git add file &&
1299+
git commit -am "Initial commit" &&
1300+
git tag initial &&
1301+
echo "new line" >>file &&
1302+
git commit -am "First change" &&
1303+
echo "another new line" >>file &&
1304+
git commit -am "Second change" &&
1305+
git tag final
1306+
)
1307+
'
1308+
1309+
test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
1310+
(
1311+
cd git-bisect &&
1312+
test_completion "git bisect start " <<-\EOF
1313+
HEAD Z
1314+
final Z
1315+
initial Z
1316+
master Z
1317+
EOF
1318+
)
1319+
'
1320+
1321+
# Note that these arguments are <pathspec>s, which in practice the fallback
1322+
# completion (not the git completion) later ends up completing as paths.
1323+
test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
1324+
(
1325+
cd git-bisect &&
1326+
test_completion "git bisect start final initial -- " ""
1327+
)
1328+
'
1329+
1330+
test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
1331+
(
1332+
cd git-bisect &&
1333+
git bisect start --term-new=custom_new --term-old=custom_old final initial
1334+
)
1335+
'
1336+
1337+
test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
1338+
(
1339+
cd git-bisect &&
1340+
test_completion "git bisect " <<-\EOF
1341+
start Z
1342+
bad Z
1343+
custom_new Z
1344+
custom_old Z
1345+
new Z
1346+
good Z
1347+
old Z
1348+
terms Z
1349+
skip Z
1350+
reset Z
1351+
visualize Z
1352+
replay Z
1353+
log Z
1354+
run Z
1355+
help Z
1356+
EOF
1357+
)
1358+
'
1359+
1360+
test_expect_success 'git-bisect - options to terms subcommand are candidates' '
1361+
(
1362+
cd git-bisect &&
1363+
test_completion "git bisect terms --" <<-\EOF
1364+
--term-bad Z
1365+
--term-good Z
1366+
--term-new Z
1367+
--term-old Z
1368+
EOF
1369+
)
1370+
'
1371+
1372+
test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
1373+
(
1374+
cd git-bisect &&
1375+
# The completion used for git-log and here does not complete
1376+
# every git-log option, so rather than hope to stay in sync
1377+
# with exactly what it does we will just spot-test here.
1378+
test_completion "git bisect visualize --sta" <<-\EOF &&
1379+
--stat Z
1380+
EOF
1381+
test_completion "git bisect visualize --summar" <<-\EOF
1382+
--summary Z
1383+
EOF
1384+
)
1385+
'
1386+
1387+
test_expect_success 'git-bisect - view subcommand is not a candidate' '
1388+
(
1389+
cd git-bisect &&
1390+
test_completion "git bisect vi" <<-\EOF
1391+
visualize Z
1392+
EOF
1393+
)
1394+
'
1395+
1396+
test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
1397+
(
1398+
cd git-bisect &&
1399+
# The completion used for git-log and here does not complete
1400+
# every git-log option, so rather than hope to stay in sync
1401+
# with exactly what it does we will just spot-test here.
1402+
test_completion "git bisect view --sta" <<-\EOF &&
1403+
--stat Z
1404+
EOF
1405+
test_completion "git bisect view --summar" <<-\EOF
1406+
--summary Z
1407+
EOF
1408+
)
1409+
'
1410+
12701411
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
12711412
test_completion "git checkout " <<-\EOF
12721413
HEAD Z

0 commit comments

Comments
 (0)