Skip to contentSkip to conversation

completion: __git_config_get_set_variables() handle values with spaces

PATCH In review Stephen Boyd 1 participant 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 completion: __git_config_get_set_variables() handle values with spaces

Commit 0065236 (bash completion: complete variable names for "git config" with options 2009-05-08) implemented its config variable search wrong. When a config contains a value with a space and a period (.) in it, completion erroneously thinks that line in the configuration is multiple config variables.

For example

 $ cat .git/config
   format.cc = Junio C Hamano <[email protected]>
 $ git config --unset <TAB>
   format.cc
   <[email protected]>

Instead of using a for loop splitting across spaces, pipe each line to a while read loop and beef up the case statement to match only 'config.variable=value'.

---
 contrib/completion/git-completion.bash |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
contrib/completion/git-completion.bash +6 -5
index b60cb68..d676f9d 100755
@@ -1357,11 +1357,12 @@ __git_config_get_set_variables ()
 		c=$((--c))
 	done
 
-	for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
-			2>/dev/null); do
-		case "$i" in
-		*.*)
-			echo "${i/=*/}"
+	git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
+	while read line
+	do
+		case "$line" in
+		*.*=*)
+			echo "${line/=*/}"
 			;;
 		esac
 	done
Signature · 1 line
1.6.3.3.353.g4f2b1
#1 lore raw
Quoted 5 lines · Stephen Boyd

For example

 $ cat .git/config
   format.cc = Junio C Hamano <[email protected]>

Sorry this is inaccurate. Something more like

$ cat .git/config
[format]
        cc = Junio C Hamano <[email protected]>

would be correct, but I think you got the point.