From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: pclouds@gmail.com
Cc: git@vger.kernel.org, gitster@pobox.com, sunshine@sunshineco.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCH v3 0/3] ompletion: complete all possible -no-<options>
Date: Wed, 6 Jun 2018 11:41:36 +0200 [thread overview]
Message-ID: <20180606094139.30906-1-pclouds@gmail.com> (raw)
In-Reply-To: <20180527083828.6919-1-pclouds@gmail.com>
v3 fixes an annoying bug in 3/3. If you do "git commit --fi<tab>"
then the "fi" part is eaten up by bash and you got back to
"git commit --" on the command line.
This is because we give COMPREPLY with two options "--fixup" and
"--no-...". The second one forces the common prefix "--" for both
of them, instead of "--fi". Bash does the rest according to the book.
Some tests are added to verify new behavior in __gitcomp and make sure
this does not happen again.
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4eef353ee2..425d06256f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -286,7 +286,10 @@ __gitcomp ()
local c i=0 IFS=$' \t\n'
for c in $1; do
if [[ $c == "--" ]]; then
- COMPREPLY[i++]="${2-}--no-...${4-} "
+ c="--no-...${4-}"
+ if [[ $c == "$cur_"* ]]; then
+ COMPREPLY[i++]="${2-}$c "
+ fi
break
fi
c="$c${4-}"
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index eb4a43584a..157ee7085d 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -459,6 +459,42 @@ test_expect_success '__gitcomp - suffix' '
EOF
'
+test_expect_success '__gitcomp - ignore optional negative options' '
+ test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
+ --abc Z
+ --def Z
+ --no-one Z
+ --no-... Z
+ EOF
+'
+
+test_expect_success '__gitcomp - ignore/narrow optional negative options' '
+ test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
+ --abc Z
+ --abcdef Z
+ EOF
+'
+
+test_expect_success '__gitcomp - ignore/narrow optional negative options' '
+ test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
+ --no-one Z
+ --no-... Z
+ EOF
+'
+
+test_expect_success '__gitcomp - expand all negative options' '
+ test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
+ --no-one Z
+ --no-two Z
+ EOF
+'
+
+test_expect_success '__gitcomp - expand/narrow all negative options' '
+ test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
+ --no-one Z
+ EOF
+'
+
test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
__gitcomp "$invalid_variable_name"
'
Nguyễn Thái Ngọc Duy (3):
parse-options: option to let --git-completion-helper show negative
form
completion: suppress some -no- options
completion: collapse extra --no-.. options
builtin/checkout.c | 10 +++--
contrib/completion/git-completion.bash | 61 ++++++++++++++++----------
parse-options.c | 58 ++++++++++++++++++++++--
t/t9902-completion.sh | 41 ++++++++++++++++-
4 files changed, 136 insertions(+), 34 deletions(-)
--
2.18.0.rc0.333.g22e6ee6cdf
next prev parent reply other threads:[~2018-06-06 9:42 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 ` [PATCH v2 1/3] parse-options: option to let --git-completion-helper show negative form Nguyễn Thái Ngọc Duy
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 ` Nguyễn Thái Ngọc Duy [this message]
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=20180606094139.30906-1-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.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).