From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: pclouds@gmail.com
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v2 1/3] parse-options: option to let --git-completion-helper show negative form
Date: Sun, 27 May 2018 10:38:26 +0200 [thread overview]
Message-ID: <20180527083828.6919-2-pclouds@gmail.com> (raw)
In-Reply-To: <20180527083828.6919-1-pclouds@gmail.com>
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>
---
contrib/completion/git-completion.bash | 38 ++++++++++----------------
parse-options.c | 22 ++++++++++++---
t/t9902-completion.sh | 16 +++++++++--
3 files changed, 46 insertions(+), 30 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 961a0ed76f..952e660f06 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1126,7 +1126,7 @@ _git_am ()
return
;;
--*)
- __gitcomp_builtin am "--no-utf8" \
+ __gitcomp_builtin am "" \
"$__git_am_inprogress_options"
return
esac
@@ -1226,9 +1226,7 @@ _git_branch ()
__git_complete_refs --cur="${cur##--set-upstream-to=}"
;;
--*)
- __gitcomp_builtin branch "--no-color --no-abbrev
- --no-track --no-column
- "
+ __gitcomp_builtin branch
;;
*)
if [ $only_local_ref = "y" -a $has_r = "n" ]; then
@@ -1269,7 +1267,7 @@ _git_checkout ()
__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
@@ -1332,7 +1330,7 @@ _git_clone ()
{
case "$cur" in
--*)
- __gitcomp_builtin clone "--no-single-branch"
+ __gitcomp_builtin clone
return
;;
esac
@@ -1365,7 +1363,7 @@ _git_commit ()
return
;;
--*)
- __gitcomp_builtin commit "--no-edit --verify"
+ __gitcomp_builtin commit
return
esac
@@ -1468,7 +1466,7 @@ _git_fetch ()
return
;;
--*)
- __gitcomp_builtin fetch "--no-tags"
+ __gitcomp_builtin fetch
return
;;
esac
@@ -1505,7 +1503,7 @@ _git_fsck ()
{
case "$cur" in
--*)
- __gitcomp_builtin fsck "--no-reflogs"
+ __gitcomp_builtin fsck
return
;;
esac
@@ -1612,7 +1610,7 @@ _git_ls_files ()
{
case "$cur" in
--*)
- __gitcomp_builtin ls-files "--no-empty-directory"
+ __gitcomp_builtin ls-files
return
;;
esac
@@ -1763,12 +1761,7 @@ _git_merge ()
case "$cur" in
--*)
- __gitcomp_builtin merge "--no-rerere-autoupdate
- --no-commit --no-edit --no-ff
- --no-log --no-progress
- --no-squash --no-stat
- --no-verify-signatures
- "
+ __gitcomp_builtin merge
return
esac
__git_complete_refs
@@ -1867,10 +1860,7 @@ _git_pull ()
return
;;
--*)
- __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
- --no-ff --no-log --no-progress --no-rebase
- --no-squash --no-stat --no-tags
- --no-verify-signatures"
+ __gitcomp_builtin pull
return
;;
@@ -2061,7 +2051,7 @@ _git_status ()
return
;;
--*)
- __gitcomp_builtin status "--no-column"
+ __gitcomp_builtin status
return
;;
esac
@@ -2615,7 +2605,7 @@ _git_remote ()
case "$subcommand,$cur" in
add,--*)
- __gitcomp_builtin remote_add "--no-tags"
+ __gitcomp_builtin remote_add
;;
add,*)
;;
@@ -2695,7 +2685,7 @@ _git_revert ()
fi
case "$cur" in
--*)
- __gitcomp_builtin revert "--no-edit" \
+ __gitcomp_builtin revert "" \
"$__git_revert_inprogress_options"
return
;;
@@ -2765,7 +2755,7 @@ _git_show_branch ()
{
case "$cur" in
--*)
- __gitcomp_builtin show-branch "--no-color"
+ __gitcomp_builtin show-branch
return
;;
esac
diff --git a/parse-options.c b/parse-options.c
index 0f7059a8ab..b86612148f 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -427,15 +427,12 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
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,
const struct option *opts)
{
for (; opts->type != OPTION_END; opts++) {
const char *suffix = "";
+ int has_unset_form = 0;
if (!opts->long_name)
continue;
@@ -450,6 +447,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
case OPTION_INTEGER:
case OPTION_MAGNITUDE:
case OPTION_CALLBACK:
+ has_unset_form = 1;
+
if (opts->flags & PARSE_OPT_NOARG)
break;
if (opts->flags & PARSE_OPT_OPTARG)
@@ -458,12 +457,27 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
break;
suffix = "=";
break;
+ case OPTION_BIT:
+ case OPTION_NEGBIT:
+ case OPTION_COUNTUP:
+ case OPTION_SET_INT:
+ has_unset_form = 1;
+ break;
default:
break;
}
if (opts->flags & PARSE_OPT_COMP_ARG)
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);
exit(0);
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 1b34caa1e1..07c3e3b760 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1237,20 +1237,31 @@ test_expect_success 'double dash "git" itself' '
test_expect_success 'double dash "git checkout"' '
test_completion "git checkout --" <<-\EOF
--quiet Z
+ --no-quiet Z
--detach Z
+ --no-detach Z
--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
- --progress Z
- --no-track Z
--no-recurse-submodules Z
+ --progress Z
+ --no-progress Z
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_completion "git version --" <<-\EOF
--build-options Z
+ --no-build-options Z
EOF
'
--
2.17.0.705.g3525833791
next prev parent reply other threads:[~2018-05-27 8:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 18:13 [PATCH/RFC] completion: complete all possible -no-<options> Nguyễn Thái Ngọc Duy
2018-04-18 3:43 ` Junio C Hamano
2018-04-18 15:08 ` Duy Nguyen
2018-04-23 5:36 ` Eric Sunshine
2018-05-08 15:24 ` Duy Nguyen
2018-05-08 16:39 ` Stefan Beller
2018-05-09 3:20 ` Aaron Schrab
2018-05-14 17:14 ` Duy Nguyen
2018-05-14 3:33 ` Eric Sunshine
2018-05-14 16:39 ` Duy Nguyen
2018-05-14 17:03 ` Andreas Heiduk
2018-05-14 17:26 ` Duy Nguyen
2018-05-14 19:58 ` Andreas Heiduk
2018-05-27 8:38 ` [PATCH v2 0/3] " Nguyễn Thái Ngọc Duy
2018-05-27 8:38 ` Nguyễn Thái Ngọc Duy [this message]
2018-05-27 8:38 ` [PATCH v2 2/3] completion: suppress some -no- options Nguyễn Thái Ngọc Duy
2018-05-27 8:38 ` [PATCH v2 3/3] completion: collapse extra --no-.. options Nguyễn Thái Ngọc Duy
2018-05-29 18:48 ` Stefan Beller
2018-05-29 19:04 ` Duy Nguyen
2018-06-06 9:41 ` [PATCH v3 0/3] ompletion: complete all possible -no-<options> Nguyễn Thái Ngọc Duy
2018-06-06 9:41 ` [PATCH v3 1/3] parse-options: option to let --git-completion-helper show negative form Nguyễn Thái Ngọc Duy
2018-06-06 9:41 ` [PATCH v3 2/3] completion: suppress some -no- options Nguyễn Thái Ngọc Duy
2018-06-06 9:41 ` [PATCH v3 3/3] completion: collapse extra --no-.. options Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180527083828.6919-2-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).