bash completion: use read -r everywhere

We use the 'read' command without -r, so that it treats '\' as an escape character, in several places. This breaks the loop reading refnames from git-for-each-ref in __git_refs() if there are refnames such as "foo'bar", in which case for-each-ref helpfully quotes them as $ git update-ref "refs/remotes/test/foo'bar" HEAD $ git for-each-ref --shell --format="ref=%(refname:short)" "refs/remotes" ref='test/foo'\''bar' Interpolating the \' here will read "ref='test/foo'''bar'" instead, and eval then chokes on the unbalanced quotes. However, since none of the read loops _want_ to have backslashes interpolated, it's much safer to use read -r everywhere. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Dec 21, 2011 at 16:54 UTC 6f2dd720b68ee8df0afae92e96001c8d3f14c1dc
1 file changed +6 -6
contrib/completion/git-completion.bash
+6 -6
@@ -111,7 +111,7 @@ __git_ps1_show_upstream ()
111
112 # get some config options from git-config
113 local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
114 - while read key value; do
114 + while read -r key value; do
115 case "$key" in
116 bash.showupstream)
117 GIT_PS1_SHOWUPSTREAM="$value"
@@ -589,7 +589,7 @@ __git_refs ()
589 local ref entry
590 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
591 "refs/remotes/" | \
592 - while read entry; do
592 + while read -r entry; do
593 eval "$entry"
594 ref="${ref#*/}"
595 if [[ "$ref" == "$cur"* ]]; then
@@ -602,7 +602,7 @@ __git_refs ()
602 case "$cur" in
603 refs|refs/*)
604 git ls-remote "$dir" "$cur*" 2>/dev/null | \
605 - while read hash i; do
605 + while read -r hash i; do
606 case "$i" in
607 *^{}) ;;
608 *) echo "$i" ;;
@@ -611,7 +611,7 @@ __git_refs ()
611 ;;
612 *)
613 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
614 - while read hash i; do
614 + while read -r hash i; do
615 case "$i" in
616 *^{}) ;;
617 refs/*) echo "${i#refs/*/}" ;;
@@ -636,7 +636,7 @@ __git_refs_remotes ()
636 {
637 local i hash
638 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
639 - while read hash i; do
639 + while read -r hash i; do
640 echo "$i:refs/remotes/$1/${i#refs/heads/}"
641 done
642 }
@@ -1863,7 +1863,7 @@ __git_config_get_set_variables ()
1863 done
1864
1865 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1866 - while read line
1866 + while read -r line
1867 do
1868 case "$line" in
1869 *.*=*)