prompt: fix show upstream with svn and zsh

Currently the __git_ps1 git prompt gives the following error with a repository converted by git-svn, when used with zsh: __git_ps1_show_upstream:19: bad pattern: svn_remote[ __git_ps1_show_upstream:45: bad substitution To reproduce the problem, the __git_ps1_show_upstream function can be executed in a repository converted with git-svn. Both those errors are triggered by spaces after the '['. Zsh also doesn't support initializing an array with `local var=(...)`. This triggers the following error: __git_ps1_show_upstream:41: bad pattern: svn_upstream=(commit Use local -a var=(...) instead to make is compatible. This was introduced by 6d158cba (bash completion: Support "divergence from upstream" messages in __git_ps1), when the script was for bash only. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Acked-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed May 22, 2013 at 09:40 UTC d0583da838afbc5e039b9f0cbbb9b1fb3aa1f1ae
1 file changed +4 -3
contrib/completion/git-prompt.sh
+4 -3
@@ -124,7 +124,7 @@ __git_ps1_show_upstream ()
124 fi
125 ;;
126 svn-remote.*.url)
127 - svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
127 + svn_remote[$((${#svn_remote[@]} + 1))]="$value"
128 svn_url_pattern+="\\|$value"
129 upstream=svn+git # default upstream is SVN if available, else git
130 ;;
@@ -146,10 +146,11 @@ __git_ps1_show_upstream ()
146 svn*)
147 # get the upstream from the "git-svn-id: ..." in a commit message
148 # (git-svn uses essentially the same procedure internally)
149 - local svn_upstream=($(git log --first-parent -1 \
149 + local -a svn_upstream
150 + svn_upstream=($(git log --first-parent -1 \
151 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
152 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
152 - svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
153 + svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
154 svn_upstream=${svn_upstream%@*}
155 local n_stop="${#svn_remote[@]}"
156 for ((n=1; n <= n_stop; n++)); do