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

[PATCH 2/4] completion: bash: add correct suffix in variables

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Nov 19, 2020, 01:52 UTC
Message-ID
<20201119015209.1155170-3-felipe.contreras@gmail.com>
In-Reply-To
<20201119015209.1155170-1-felipe.contreras@gmail.com>

__gitcomp automatically adds a suffix, but __gitcomp_nl and others don't, we need to specify a space by default.

Can be tested with:
  git config branch.autoSetupMe<tab>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 6 +++---
 t/t9902-completion.sh                  | 7 +++++++
 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b866b68b3c..bbdb46d87e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2618,7 +2618,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	guitool.*.*)
@@ -2652,7 +2652,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__git_compute_all_commands
-		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	remote.*.*)
@@ -2668,7 +2668,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	url.*.*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 2be9190425..4a3d3d1597 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2293,6 +2293,13 @@ test_expect_success 'git config - value' '
 	EOF
 '
 
+test_expect_success 'git config - direct completions' '
+	test_completion "git config branch.autoSetup" <<-\EOF
+	branch.autoSetupMerge Z
+	branch.autoSetupRebase Z
+	EOF
+'
+
 test_expect_success 'git -c - section' '
 	test_completion "git -c br" <<-\EOF
 	branch.Z
-- 
2.29.2
Previous: Felipe ContrerasNext: Felipe Contreras
Message 3 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.