# [PATCH v2] Fix git-completion.bash for use in zsh

4 messages from 2012-03-21 to 2012-04-07. Participants: Alex Merry, Junio C Hamano, Felipe Contreras.
Thread: https://gitlist.dev/t/30015

## Alex Merry, 2012-03-21 11:06

Subject: [PATCH v2] Fix git-completion.bash for use in zsh
Message-ID: <1332327960-5208-1-git-send-email-dev@randomguy3.me.uk>
URL: https://gitlist.dev/e/1332327960-5208-1-git-send-email-dev%40randomguy3.me.uk

```
zsh treats
  local some_var=()
as a function declaration, rather than an array declaration (although
its documentation does not suggest that this should be the case).

With zsh 4.3.15 on Fedora Core 15, this causes
  __git_ps1 " (%s)"
to produce the message
  local:2: command not found: svn_url_pattern
when GIT_PS1_SHOWUPSTREAM="auto", due to the line
  local svn_remote=() svn_url_pattern count n

Simply doing
  local some_var
  some_var=()
fixes the issue.

Signed-off-by: Alex Merry <dev@randomguy3.me.uk>
---

Here it is again, with a better commit message, and no whitespace issues (hopefully).


 contrib/completion/git-completion.bash |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0acbdda..092a34f 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -94,8 +94,9 @@ __gitdir ()
 __git_ps1_show_upstream ()
 {
 	local key value
-	local svn_remote=() svn_url_pattern count n
+	local svn_remote svn_url_pattern count n
 	local upstream=git legacy="" verbose=""
+	svn_remote=()
 
 	# get some config options from git-config
 	local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
-- 
1.7.6.5

```

## Junio C Hamano, 2012-03-21 17:05

Subject: Re: [PATCH v2] Fix git-completion.bash for use in zsh
Message-ID: <7vaa393mvc.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaa393mvc.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1332327960-5208-1-git-send-email-dev@randomguy3.me.uk>

```
Alex Merry <dev@randomguy3.me.uk> writes:

> zsh treats
>   local some_var=()
> as a function declaration, rather than an array declaration (although
> its documentation does not suggest that this should be the case).
>
> With zsh 4.3.15 on Fedora Core 15, this causes
>   __git_ps1 " (%s)"
> to produce the message
>   local:2: command not found: svn_url_pattern
> when GIT_PS1_SHOWUPSTREAM="auto", due to the line
>   local svn_remote=() svn_url_pattern count n

Thanks, will queue.  Felipe, comments?

> Simply doing
>   local some_var
>   some_var=()
> fixes the issue.
>
> Signed-off-by: Alex Merry <dev@randomguy3.me.uk>
> ---
>
> Here it is again, with a better commit message, and no whitespace issues (hopefully).
>
>
>  contrib/completion/git-completion.bash |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0acbdda..092a34f 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -94,8 +94,9 @@ __gitdir ()
>  __git_ps1_show_upstream ()
>  {
>  	local key value
> -	local svn_remote=() svn_url_pattern count n
> +	local svn_remote svn_url_pattern count n
>  	local upstream=git legacy="" verbose=""
> +	svn_remote=()
>  
>  	# get some config options from git-config
>  	local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"

```

## Felipe Contreras, 2012-03-25 17:47

Subject: Re: [PATCH v2] Fix git-completion.bash for use in zsh
Message-ID: <CAMP44s3_aZ39n6L15ZUNyw8B_6ab+=_Hm8-KPz6WM26GweJCmg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s3_aZ39n6L15ZUNyw8B_6ab%2B%3D_Hm8-KPz6WM26GweJCmg%40mail.gmail.com
In-Reply-To: <7vaa393mvc.fsf@alter.siamese.dyndns.org>

```
On Wed, Mar 21, 2012 at 7:05 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Alex Merry <dev@randomguy3.me.uk> writes:
>
>> zsh treats
>>   local some_var=()
>> as a function declaration, rather than an array declaration (although
>> its documentation does not suggest that this should be the case).
>>
>> With zsh 4.3.15 on Fedora Core 15, this causes
>>   __git_ps1 " (%s)"
>> to produce the message
>>   local:2: command not found: svn_url_pattern
>> when GIT_PS1_SHOWUPSTREAM="auto", due to the line
>>   local svn_remote=() svn_url_pattern count n
>
> Thanks, will queue.  Felipe, comments?

Looks good to me. Also, I tested this, and it worked.

-- 
Felipe Contreras

```

## Felipe Contreras, 2012-04-07 13:09

Subject: Re: [PATCH v2] Fix git-completion.bash for use in zsh
Message-ID: <CAMP44s1H74_2pewqLrkz9cmiguxH1=Ayz-5fn5_HgUCqbbB9rw@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s1H74_2pewqLrkz9cmiguxH1%3DAyz-5fn5_HgUCqbbB9rw%40mail.gmail.com
In-Reply-To: <1332327960-5208-1-git-send-email-dev@randomguy3.me.uk>

```
On Wed, Mar 21, 2012 at 1:06 PM, Alex Merry <dev@randomguy3.me.uk> wrote:

>  __git_ps1_show_upstream ()
>  {
>        local key value
> -       local svn_remote=() svn_url_pattern count n
> +       local svn_remote svn_url_pattern count n
>        local upstream=git legacy="" verbose=""
> +       svn_remote=()
>
>        # get some config options from git-config
>        local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
> --

Actually, a more proper way to do this is 'local -a svn_remote'.

Cheers.

-- 
Felipe Contreras

```
