parse-options: option to let --git-completion-helper show negative form
When 7fb6aefd2a (Merge branch 'nd/parseopt-completion' - 2018-03-14) is merged, the completion for negative form is left out because the series is alread long and it could be done in a follow up series. This is it. --git-completion-helper now provides --no-xxx so that git-completion.bash can drop the extra custom --no-xxx in the script. It adds a lot more --no-xxx than what's current provided by the git-completion.bash script. We'll trim that down later. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 27, 2018 at 10:38 UTC
2b1c01d22ef280ef3a6efd70db2b9aa58359ee36
3 files changed
+46
-30
contrib/completion/git-completion.bash
+14
-24
@@ -1126,7 +1126,7 @@ _git_am ()
1126
return
1127
;;
1128
--*)
1129
- __gitcomp_builtin am "--no-utf8" \
1129
+ __gitcomp_builtin am "" \
1130
"$__git_am_inprogress_options"
1131
return
1132
esac
@@ -1226,9 +1226,7 @@ _git_branch ()
1226
__git_complete_refs --cur="${cur##--set-upstream-to=}"
1227
;;
1228
--*)
1229
- __gitcomp_builtin branch "--no-color --no-abbrev
1230
- --no-track --no-column
1231
- "
1229
+ __gitcomp_builtin branch
1230
;;
1231
*)
1232
if [ $only_local_ref = "y" -a $has_r = "n" ]; then
@@ -1269,7 +1267,7 @@ _git_checkout ()
1267
__gitcomp "diff3 merge" "" "${cur##--conflict=}"
1268
;;
1269
--*)
1272
- __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1270
+ __gitcomp_builtin checkout
1271
;;
1272
*)
1273
# check if --track, --no-track, or --no-guess was specified
@@ -1332,7 +1330,7 @@ _git_clone ()
1330
{
1331
case "$cur" in
1332
--*)
1335
- __gitcomp_builtin clone "--no-single-branch"
1333
+ __gitcomp_builtin clone
1334
return
1335
;;
1336
esac
@@ -1365,7 +1363,7 @@ _git_commit ()
1363
return
1364
;;
1365
--*)
1368
- __gitcomp_builtin commit "--no-edit --verify"
1366
+ __gitcomp_builtin commit
1367
return
1368
esac
1369
@@ -1468,7 +1466,7 @@ _git_fetch ()
1466
return
1467
;;
1468
--*)
1471
- __gitcomp_builtin fetch "--no-tags"
1469
+ __gitcomp_builtin fetch
1470
return
1471
;;
1472
esac
@@ -1505,7 +1503,7 @@ _git_fsck ()
1503
{
1504
case "$cur" in
1505
--*)
1508
- __gitcomp_builtin fsck "--no-reflogs"
1506
+ __gitcomp_builtin fsck
1507
return
1508
;;
1509
esac
@@ -1612,7 +1610,7 @@ _git_ls_files ()
1610
{
1611
case "$cur" in
1612
--*)
1615
- __gitcomp_builtin ls-files "--no-empty-directory"
1613
+ __gitcomp_builtin ls-files
1614
return
1615
;;
1616
esac
@@ -1763,12 +1761,7 @@ _git_merge ()
1761
1762
case "$cur" in
1763
--*)
1766
- __gitcomp_builtin merge "--no-rerere-autoupdate
1767
- --no-commit --no-edit --no-ff
1768
- --no-log --no-progress
1769
- --no-squash --no-stat
1770
- --no-verify-signatures
1771
- "
1764
+ __gitcomp_builtin merge
1765
return
1766
esac
1767
__git_complete_refs
@@ -1867,10 +1860,7 @@ _git_pull ()
1860
return
1861
;;
1862
--*)
1870
- __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1871
- --no-ff --no-log --no-progress --no-rebase
1872
- --no-squash --no-stat --no-tags
1873
- --no-verify-signatures"
1863
+ __gitcomp_builtin pull
1864
1865
return
1866
;;
@@ -2061,7 +2051,7 @@ _git_status ()
2051
return
2052
;;
2053
--*)
2064
- __gitcomp_builtin status "--no-column"
2054
+ __gitcomp_builtin status
2055
return
2056
;;
2057
esac
@@ -2615,7 +2605,7 @@ _git_remote ()
2605
2606
case "$subcommand,$cur" in
2607
add,--*)
2618
- __gitcomp_builtin remote_add "--no-tags"
2608
+ __gitcomp_builtin remote_add
2609
;;
2610
add,*)
2611
;;
@@ -2695,7 +2685,7 @@ _git_revert ()
2685
fi
2686
case "$cur" in
2687
--*)
2698
- __gitcomp_builtin revert "--no-edit" \
2688
+ __gitcomp_builtin revert "" \
2689
"$__git_revert_inprogress_options"
2690
return
2691
;;
@@ -2765,7 +2755,7 @@ _git_show_branch ()
2755
{
2756
case "$cur" in
2757
--*)
2768
- __gitcomp_builtin show-branch "--no-color"
2758
+ __gitcomp_builtin show-branch
2759
return
2760
;;
2761
esac
parse-options.c
+18
-4
@@ -427,15 +427,12 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
427
parse_options_check(options);
428
}
429
430
-/*
431
- * TODO: we are not completing the --no-XXX form yet because there are
432
- * many options that do not suppress it properly.
433
- */
430
static int show_gitcomp(struct parse_opt_ctx_t *ctx,
431
const struct option *opts)
432
{
433
for (; opts->type != OPTION_END; opts++) {
434
const char *suffix = "";
435
+ int has_unset_form = 0;
436
437
if (!opts->long_name)
438
continue;
@@ -450,6 +447,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
447
case OPTION_INTEGER:
448
case OPTION_MAGNITUDE:
449
case OPTION_CALLBACK:
450
+ has_unset_form = 1;
451
+
452
if (opts->flags & PARSE_OPT_NOARG)
453
break;
454
if (opts->flags & PARSE_OPT_OPTARG)
@@ -458,12 +457,27 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
457
break;
458
suffix = "=";
459
break;
460
+ case OPTION_BIT:
461
+ case OPTION_NEGBIT:
462
+ case OPTION_COUNTUP:
463
+ case OPTION_SET_INT:
464
+ has_unset_form = 1;
465
+ break;
466
default:
467
break;
468
}
469
if (opts->flags & PARSE_OPT_COMP_ARG)
470
suffix = "=";
471
printf(" --%s%s", opts->long_name, suffix);
472
+
473
+ if (has_unset_form && !(opts->flags & PARSE_OPT_NONEG)) {
474
+ const char *name;
475
+
476
+ if (skip_prefix(opts->long_name, "no-", &name))
477
+ printf(" --%s", name);
478
+ else
479
+ printf(" --no-%s", opts->long_name);
480
+ }
481
}
482
fputc('\n', stdout);
483
exit(0);
t/t9902-completion.sh
+14
-2
@@ -1237,20 +1237,31 @@ test_expect_success 'double dash "git" itself' '
1237
test_expect_success 'double dash "git checkout"' '
1238
test_completion "git checkout --" <<-\EOF
1239
--quiet Z
1240
+ --no-quiet Z
1241
--detach Z
1242
+ --no-detach Z
1243
--track Z
1244
+ --no-track Z
1245
--orphan=Z
1246
+ --no-orphan Z
1247
--ours Z
1248
+ --no-ours Z
1249
--theirs Z
1250
+ --no-theirs Z
1251
--merge Z
1252
+ --no-merge Z
1253
--conflict=Z
1254
+ --no-conflict Z
1255
--patch Z
1256
+ --no-patch Z
1257
--ignore-skip-worktree-bits Z
1258
+ --no-ignore-skip-worktree-bits Z
1259
--ignore-other-worktrees Z
1260
+ --no-ignore-other-worktrees Z
1261
--recurse-submodules Z
1251
- --progress Z
1252
- --no-track Z
1262
--no-recurse-submodules Z
1263
+ --progress Z
1264
+ --no-progress Z
1265
EOF
1266
'
1267
@@ -1457,6 +1468,7 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
1468
test_expect_success 'completion without explicit _git_xxx function' '
1469
test_completion "git version --" <<-\EOF
1470
--build-options Z
1471
+ --no-build-options Z
1472
EOF
1473
'
1474