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>
This commit is contained in:
committed by
Junio C Hamano
parent
e144d126d7
commit
2b1c01d22e
@ -1126,7 +1126,7 @@ _git_am ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin am "--no-utf8" \
|
__gitcomp_builtin am "" \
|
||||||
"$__git_am_inprogress_options"
|
"$__git_am_inprogress_options"
|
||||||
return
|
return
|
||||||
esac
|
esac
|
||||||
@ -1226,9 +1226,7 @@ _git_branch ()
|
|||||||
__git_complete_refs --cur="${cur##--set-upstream-to=}"
|
__git_complete_refs --cur="${cur##--set-upstream-to=}"
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin branch "--no-color --no-abbrev
|
__gitcomp_builtin branch
|
||||||
--no-track --no-column
|
|
||||||
"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ $only_local_ref = "y" -a $has_r = "n" ]; then
|
if [ $only_local_ref = "y" -a $has_r = "n" ]; then
|
||||||
@ -1269,7 +1267,7 @@ _git_checkout ()
|
|||||||
__gitcomp "diff3 merge" "" "${cur##--conflict=}"
|
__gitcomp "diff3 merge" "" "${cur##--conflict=}"
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin checkout "--no-track --no-recurse-submodules"
|
__gitcomp_builtin checkout
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# check if --track, --no-track, or --no-guess was specified
|
# check if --track, --no-track, or --no-guess was specified
|
||||||
@ -1332,7 +1330,7 @@ _git_clone ()
|
|||||||
{
|
{
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin clone "--no-single-branch"
|
__gitcomp_builtin clone
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -1365,7 +1363,7 @@ _git_commit ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin commit "--no-edit --verify"
|
__gitcomp_builtin commit
|
||||||
return
|
return
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -1468,7 +1466,7 @@ _git_fetch ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin fetch "--no-tags"
|
__gitcomp_builtin fetch
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -1505,7 +1503,7 @@ _git_fsck ()
|
|||||||
{
|
{
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin fsck "--no-reflogs"
|
__gitcomp_builtin fsck
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -1612,7 +1610,7 @@ _git_ls_files ()
|
|||||||
{
|
{
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin ls-files "--no-empty-directory"
|
__gitcomp_builtin ls-files
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -1763,12 +1761,7 @@ _git_merge ()
|
|||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin merge "--no-rerere-autoupdate
|
__gitcomp_builtin merge
|
||||||
--no-commit --no-edit --no-ff
|
|
||||||
--no-log --no-progress
|
|
||||||
--no-squash --no-stat
|
|
||||||
--no-verify-signatures
|
|
||||||
"
|
|
||||||
return
|
return
|
||||||
esac
|
esac
|
||||||
__git_complete_refs
|
__git_complete_refs
|
||||||
@ -1867,10 +1860,7 @@ _git_pull ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin pull "--no-autostash --no-commit --no-edit
|
__gitcomp_builtin pull
|
||||||
--no-ff --no-log --no-progress --no-rebase
|
|
||||||
--no-squash --no-stat --no-tags
|
|
||||||
--no-verify-signatures"
|
|
||||||
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
@ -2061,7 +2051,7 @@ _git_status ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin status "--no-column"
|
__gitcomp_builtin status
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -2615,7 +2605,7 @@ _git_remote ()
|
|||||||
|
|
||||||
case "$subcommand,$cur" in
|
case "$subcommand,$cur" in
|
||||||
add,--*)
|
add,--*)
|
||||||
__gitcomp_builtin remote_add "--no-tags"
|
__gitcomp_builtin remote_add
|
||||||
;;
|
;;
|
||||||
add,*)
|
add,*)
|
||||||
;;
|
;;
|
||||||
@ -2695,7 +2685,7 @@ _git_revert ()
|
|||||||
fi
|
fi
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin revert "--no-edit" \
|
__gitcomp_builtin revert "" \
|
||||||
"$__git_revert_inprogress_options"
|
"$__git_revert_inprogress_options"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
@ -2765,7 +2755,7 @@ _git_show_branch ()
|
|||||||
{
|
{
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
__gitcomp_builtin show-branch "--no-color"
|
__gitcomp_builtin show-branch
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -427,15 +427,12 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
|
|||||||
parse_options_check(options);
|
parse_options_check(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: we are not completing the --no-XXX form yet because there are
|
|
||||||
* many options that do not suppress it properly.
|
|
||||||
*/
|
|
||||||
static int show_gitcomp(struct parse_opt_ctx_t *ctx,
|
static int show_gitcomp(struct parse_opt_ctx_t *ctx,
|
||||||
const struct option *opts)
|
const struct option *opts)
|
||||||
{
|
{
|
||||||
for (; opts->type != OPTION_END; opts++) {
|
for (; opts->type != OPTION_END; opts++) {
|
||||||
const char *suffix = "";
|
const char *suffix = "";
|
||||||
|
int has_unset_form = 0;
|
||||||
|
|
||||||
if (!opts->long_name)
|
if (!opts->long_name)
|
||||||
continue;
|
continue;
|
||||||
@ -450,6 +447,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
|
|||||||
case OPTION_INTEGER:
|
case OPTION_INTEGER:
|
||||||
case OPTION_MAGNITUDE:
|
case OPTION_MAGNITUDE:
|
||||||
case OPTION_CALLBACK:
|
case OPTION_CALLBACK:
|
||||||
|
has_unset_form = 1;
|
||||||
|
|
||||||
if (opts->flags & PARSE_OPT_NOARG)
|
if (opts->flags & PARSE_OPT_NOARG)
|
||||||
break;
|
break;
|
||||||
if (opts->flags & PARSE_OPT_OPTARG)
|
if (opts->flags & PARSE_OPT_OPTARG)
|
||||||
@ -458,12 +457,27 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
|
|||||||
break;
|
break;
|
||||||
suffix = "=";
|
suffix = "=";
|
||||||
break;
|
break;
|
||||||
|
case OPTION_BIT:
|
||||||
|
case OPTION_NEGBIT:
|
||||||
|
case OPTION_COUNTUP:
|
||||||
|
case OPTION_SET_INT:
|
||||||
|
has_unset_form = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (opts->flags & PARSE_OPT_COMP_ARG)
|
if (opts->flags & PARSE_OPT_COMP_ARG)
|
||||||
suffix = "=";
|
suffix = "=";
|
||||||
printf(" --%s%s", opts->long_name, suffix);
|
printf(" --%s%s", opts->long_name, suffix);
|
||||||
|
|
||||||
|
if (has_unset_form && !(opts->flags & PARSE_OPT_NONEG)) {
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
if (skip_prefix(opts->long_name, "no-", &name))
|
||||||
|
printf(" --%s", name);
|
||||||
|
else
|
||||||
|
printf(" --no-%s", opts->long_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputc('\n', stdout);
|
fputc('\n', stdout);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@ -1237,20 +1237,31 @@ test_expect_success 'double dash "git" itself' '
|
|||||||
test_expect_success 'double dash "git checkout"' '
|
test_expect_success 'double dash "git checkout"' '
|
||||||
test_completion "git checkout --" <<-\EOF
|
test_completion "git checkout --" <<-\EOF
|
||||||
--quiet Z
|
--quiet Z
|
||||||
|
--no-quiet Z
|
||||||
--detach Z
|
--detach Z
|
||||||
|
--no-detach Z
|
||||||
--track Z
|
--track Z
|
||||||
--orphan=Z
|
|
||||||
--ours Z
|
|
||||||
--theirs Z
|
|
||||||
--merge Z
|
|
||||||
--conflict=Z
|
|
||||||
--patch Z
|
|
||||||
--ignore-skip-worktree-bits Z
|
|
||||||
--ignore-other-worktrees Z
|
|
||||||
--recurse-submodules Z
|
|
||||||
--progress Z
|
|
||||||
--no-track Z
|
--no-track Z
|
||||||
|
--orphan=Z
|
||||||
|
--no-orphan Z
|
||||||
|
--ours Z
|
||||||
|
--no-ours Z
|
||||||
|
--theirs Z
|
||||||
|
--no-theirs Z
|
||||||
|
--merge Z
|
||||||
|
--no-merge Z
|
||||||
|
--conflict=Z
|
||||||
|
--no-conflict Z
|
||||||
|
--patch Z
|
||||||
|
--no-patch Z
|
||||||
|
--ignore-skip-worktree-bits Z
|
||||||
|
--no-ignore-skip-worktree-bits Z
|
||||||
|
--ignore-other-worktrees Z
|
||||||
|
--no-ignore-other-worktrees Z
|
||||||
|
--recurse-submodules Z
|
||||||
--no-recurse-submodules Z
|
--no-recurse-submodules Z
|
||||||
|
--progress Z
|
||||||
|
--no-progress Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -1457,6 +1468,7 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
|
|||||||
test_expect_success 'completion without explicit _git_xxx function' '
|
test_expect_success 'completion without explicit _git_xxx function' '
|
||||||
test_completion "git version --" <<-\EOF
|
test_completion "git version --" <<-\EOF
|
||||||
--build-options Z
|
--build-options Z
|
||||||
|
--no-build-options Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user