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

[PATCH v3 try4 2/4] completion: bash: fix for suboptions with value

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Aug 16, 2021, 09:10 UTC
Message-ID
<20210816091025.548095-3-felipe.contreras@gmail.com>
In-Reply-To
<20210816091025.548095-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>
Tested-by: David Aguilar <davvid@gmail.com>
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 6bcf97ce79..7aea1abda5 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -356,7 +356,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 cb057ef161..6b56e54fc3 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -540,6 +540,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"
 '
@@ -2380,6 +2389,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.32.0.48.g096519100f
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, Aug 16, 2021
  2. 1/4 completion: bash: fix prefix detection in branch.*Felipe Contreras, Aug 16, 2021
  3. 3/4 completion: bash: fix for multiple dash commandsFelipe Contreras, Aug 16, 2021
  4. 2/4 completion: bash: fix for suboptions with valueFelipe Contreras, Aug 16, 2021
  5. 4/4 completion: bash: add correct suffix in variablesFelipe Contreras, Aug 16, 2021

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.