Skip to content

Commit 6f2dd72

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3daff7c commit 6f2dd72

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

contrib/completion/git-completion.bash

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ __git_ps1_show_upstream ()
111111

112112
# get some config options from git-config
113113
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
115115
case "$key" in
116116
bash.showupstream)
117117
GIT_PS1_SHOWUPSTREAM="$value"
@@ -589,7 +589,7 @@ __git_refs ()
589589
local ref entry
590590
git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
591591
"refs/remotes/" | \
592-
while read entry; do
592+
while read -r entry; do
593593
eval "$entry"
594594
ref="${ref#*/}"
595595
if [[ "$ref" == "$cur"* ]]; then
@@ -602,7 +602,7 @@ __git_refs ()
602602
case "$cur" in
603603
refs|refs/*)
604604
git ls-remote "$dir" "$cur*" 2>/dev/null | \
605-
while read hash i; do
605+
while read -r hash i; do
606606
case "$i" in
607607
*^{}) ;;
608608
*) echo "$i" ;;
@@ -611,7 +611,7 @@ __git_refs ()
611611
;;
612612
*)
613613
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
615615
case "$i" in
616616
*^{}) ;;
617617
refs/*) echo "${i#refs/*/}" ;;
@@ -636,7 +636,7 @@ __git_refs_remotes ()
636636
{
637637
local i hash
638638
git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
639-
while read hash i; do
639+
while read -r hash i; do
640640
echo "$i:refs/remotes/$1/${i#refs/heads/}"
641641
done
642642
}
@@ -1863,7 +1863,7 @@ __git_config_get_set_variables ()
18631863
done
18641864

18651865
git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1866-
while read line
1866+
while read -r line
18671867
do
18681868
case "$line" in
18691869
*.*=*)

0 commit comments

Comments
 (0)