git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/3] ompletion: complete all possible -no-<options>

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 6, 2018, 09:41 UTC
Message-ID
<20180606094139.30906-1-pclouds@gmail.com>
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
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 20 of 23 in “completion: complete all possible -no-<options>”
  1. completion: complete all possible -no-<options>Nguyễn Thái Ngọc Duy, Apr 17, 2018
  2. Junio C HamanoApr 18, 2018
  3. Duy NguyenApr 18, 2018
  4. Eric SunshineApr 23, 2018
  5. Duy NguyenMay 8, 2018
  6. Stefan BellerMay 8, 2018
  7. Aaron SchrabMay 9, 2018
  8. Duy NguyenMay 14, 2018
  9. Eric SunshineMay 14, 2018
  10. Duy NguyenMay 14, 2018
  11. Andreas HeidukMay 14, 2018
  12. Duy NguyenMay 14, 2018
  13. Andreas HeidukMay 14, 2018
  14. 0/3 completion: complete all possible -no-<options>Nguyễn Thái Ngọc Duy, May 27, 2018
  15. 1/3 parse-options: option to let --git-completion-helper show negative formNguyễn Thái Ngọc Duy, May 27, 2018
  16. 3/3 completion: collapse extra --no-.. optionsNguyễn Thái Ngọc Duy, May 27, 2018
  17. Stefan BellerMay 29, 2018
  18. Duy NguyenMay 29, 2018
  19. 2/3 completion: suppress some -no- optionsNguyễn Thái Ngọc Duy, May 27, 2018
  20. 0/3 ompletion: complete all possible -no-<options>Nguyễn Thái Ngọc Duy, Jun 6, 2018
  21. 2/3 completion: suppress some -no- optionsNguyễn Thái Ngọc Duy, Jun 6, 2018
  22. 1/3 parse-options: option to let --git-completion-helper show negative formNguyễn Thái Ngọc Duy, Jun 6, 2018
  23. 3/3 completion: collapse extra --no-.. optionsNguyễn Thái Ngọc Duy, Jun 6, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.