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

[PATCH 3/4] completion: bash: fix for suboptions with value

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Nov 19, 2020, 01:52 UTC
Message-ID
<20201119015209.1155170-4-felipe.contreras@gmail.com>
In-Reply-To
<20201119015209.1155170-1-felipe.contreras@gmail.com>
We need to ignore options that don't start with -- as well.

Depending on the value of COMP_WORDBREAKS the last word could be duplicated otherwise.

Can be tested with:
  git merge -X diff-algorithm=<tab>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |  2 +-
 t/t9902-completion.sh                  | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index bbdb46d87e..5b2dff150d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -347,7 +347,7 @@ __gitcomp ()
 	local cur_="${3-$cur}"
 
 	case "$cur_" in
-	--*=)
+	*=)
 		;;
 	--no-*)
 		local c i=0 IFS=$' \t\n'
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 4a3d3d1597..4deda01153 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -537,6 +537,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '
 	EOF
 '
 
+test_expect_success '__gitcomp - equal skip' '
+	test_gitcomp "--option=" "--option=" <<-\EOF &&
+
+	EOF
+	test_gitcomp "option=" "option=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
 	__gitcomp "$invalid_variable_name"
 '
@@ -2342,6 +2351,12 @@ test_expect_success 'git clone --config= - value' '
 	EOF
 '
 
+test_expect_success 'options with value' '
+	test_completion "git merge -X diff-algorithm=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success 'sourcing the completion script clears cached commands' '
 	__git_compute_all_commands &&
 	verbose test -n "$__git_all_commands" &&
-- 
2.29.2
Previous: Felipe ContrerasNext: Felipe Contreras
Message 4 of 5 in “completion: bash: a bunch of fixes”
  1. 0/4 completion: bash: a bunch of fixesFelipe Contreras, Nov 19, 2020
  2. 1/4 completion: bash: fix prefix detection in branch.*Felipe Contreras, Nov 19, 2020
  3. 2/4 completion: bash: add correct suffix in variablesFelipe Contreras, Nov 19, 2020
  4. 3/4 completion: bash: fix for suboptions with valueFelipe Contreras, Nov 19, 2020
  5. 4/4 completion: bash: fix for multiple dash commandsFelipe Contreras, Nov 19, 2020

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.