completion: fix shell expansion of items

As reported by Jeroen Meijer[1]; the current code doesn't deal properly with items (tags, branches, etc.) that have ${} in them because they get expaned by bash while using compgen. A simple solution is to quote the items so they get expanded properly (\$\{\}). In order to achieve that I took bash-completion's quote() function, which is rather simple, and renamed it to __git_quote() as per Jeff King's suggestion. Solves the original problem for me. [1] http://article.gmane.org/gmane.comp.version-control.git/201596 Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Sep 20, 2012 at 04:15 UTC 25ae7cfd19c8f21721363c64163cd5d9d1135b20
1 file changed +8 -1
contrib/completion/git-completion.bash
+8 -1
@@ -225,6 +225,13 @@ _get_comp_words_by_ref ()
225 fi
226 fi
227
228 +# Quotes the argument for shell reuse
229 +__git_quote()
230 +{
231 + local quoted=${1//\'/\'\\\'\'}
232 + printf "'%s'" "$quoted"
233 +}
234 +
235 # Generates completion reply with compgen, appending a space to possible
236 # completion words, if necessary.
237 # It accepts 1 to 4 arguments:
@@ -261,7 +268,7 @@ __gitcomp ()
268 __gitcomp_nl ()
269 {
270 local IFS=$'\n'
264 - COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
271 + COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$(__git_quote "$1")" -- "${3-$cur}"))
272 }
273
274 __git_heads ()