threads / patch / 53886

patchgit-prompt: changes == to = for zsh's sake

Subject: [PATCH] git-prompt: changes == to = for zsh's sake

## tl;dr

6 messages between Jul 20, 2020 and Jul 21, 2020. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

David J. Malan via GitGitGadget· Jul 20, 2020, 23:17 UTC · lore
From: "David J. Malan" <malan@harvard.edu>

When using git-prompt.sh with Zsh, __git_ps1 currently errs when inside a repo with:

__git_ps1:96: = not found
This commit changes `==` to `=` for both Bash and Zsh.
Signed-off-by: David J. Malan <malan@harvard.edu>
---
    Changes == to = for zsh's sake in git-prompt.sh
    
    Upon installing git-prompt.sh
    [https://github.com/gitgitgadget/git/blob/master/contrib/completion/git-prompt.sh] 
    on macOS Catalina, I noticed that 
    https://github.com/gitgitgadget/git/commit/afda36dbf3b4f5a489ab44c00d5210c1fa894a40 
    seems to have introduced an issue for Zsh whereby __git_ps1 errs with
    
    __git_ps1:96: = not found
    
    when inside a repo. Changing == to = would seem to address for both Bash
    and Zsh.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-679%2Fdmalan%2Fpatch-1-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-679/dmalan/patch-1-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/679
 contrib/completion/git-prompt.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to contrib/completion/git-prompt.sh +2 −2
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index e6cd5464e5..16260bab73 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -433,7 +433,7 @@ __git_ps1 ()
 	local sparse=""
 	if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
 	   [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
-	   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
+	   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
 		sparse="|SPARSE"
 	fi
 
@@ -542,7 +542,7 @@ __git_ps1 ()
 		fi
 
 		if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
-		   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
+		   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
 			h="?"
 		fi
 

base-commit: ae46588be0cd730430dded4491246dfb4eac5557
-- 
gitgitgadget
Junio C Hamano· Jul 20, 2020, 23:58 UTC · re: David J. Malan via GitGitGadget · lore

Re: [PATCH] git-prompt: changes == to = for zsh's sake

"David J. Malan via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: "David J. Malan" <malan@harvard.edu>
> Subject: Re: [PATCH] git-prompt: changes == to = for zsh's sake
s/changes/change/
> When using git-prompt.sh with Zsh, __git_ps1 currently errs
> when inside a repo with:
>
> __git_ps1:96: = not found
OK.
> This commit changes `==` to `=` for both Bash and Zsh.

We prefer to see "why" instead of "what", as the latter can easily be read from the patch text.

    Avoid using non-portable "==" that is only understood by bash
    and not zsh to "="; that way the prompt script becomes usable
    with zsh again.
or something like that.

Elijah, I think this is a minor regression in this cycle, and the fix is obvious enough that it deserves to be in the upcoming release. Agreed?

Thank you, David, for a fix.
Show 46 quoted lines
> Signed-off-by: David J. Malan <malan@harvard.edu>
> ---
>     Changes == to = for zsh's sake in git-prompt.sh
>     
>     Upon installing git-prompt.sh
>     [https://github.com/gitgitgadget/git/blob/master/contrib/completion/git-prompt.sh] 
>     on macOS Catalina, I noticed that 
>     https://github.com/gitgitgadget/git/commit/afda36dbf3b4f5a489ab44c00d5210c1fa894a40 
>     seems to have introduced an issue for Zsh whereby __git_ps1 errs with
>     
>     __git_ps1:96: = not found
>     
>     when inside a repo. Changing == to = would seem to address for both Bash
>     and Zsh.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-679%2Fdmalan%2Fpatch-1-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-679/dmalan/patch-1-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/679
>
>  contrib/completion/git-prompt.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index e6cd5464e5..16260bab73 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -433,7 +433,7 @@ __git_ps1 ()
>  	local sparse=""
>  	if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
>  	   [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
> -	   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
> +	   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
>  		sparse="|SPARSE"
>  	fi
>  
> @@ -542,7 +542,7 @@ __git_ps1 ()
>  		fi
>  
>  		if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
> -		   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
> +		   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
>  			h="?"
>  		fi
>  
>
> base-commit: ae46588be0cd730430dded4491246dfb4eac5557
Elijah Newren· Jul 21, 2020, 00:40 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-prompt: changes == to = for zsh's sake

On Mon, Jul 20, 2020 at 4:58 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 29 quoted lines
>
> "David J. Malan via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: "David J. Malan" <malan@harvard.edu>
> > Subject: Re: [PATCH] git-prompt: changes == to = for zsh's sake
>
> s/changes/change/
>
> > When using git-prompt.sh with Zsh, __git_ps1 currently errs
> > when inside a repo with:
> >
> > __git_ps1:96: = not found
>
> OK.
>
> > This commit changes `==` to `=` for both Bash and Zsh.
>
> We prefer to see "why" instead of "what", as the latter can easily
> be read from the patch text.
>
>     Avoid using non-portable "==" that is only understood by bash
>     and not zsh to "="; that way the prompt script becomes usable
>     with zsh again.
>
> or something like that.
>
> Elijah, I think this is a minor regression in this cycle, and the
> fix is obvious enough that it deserves to be in the upcoming
> release.  Agreed?

Yeah, it's a pretty obvious and very localized fix for a regression from this cycle. I'd say putting it in the upcoming release makes sense.

> Thank you, David, for a fix.
+1.
Show 46 quoted lines
> > Signed-off-by: David J. Malan <malan@harvard.edu>
> > ---
> >     Changes == to = for zsh's sake in git-prompt.sh
> >
> >     Upon installing git-prompt.sh
> >     [https://github.com/gitgitgadget/git/blob/master/contrib/completion/git-prompt.sh]
> >     on macOS Catalina, I noticed that
> >     https://github.com/gitgitgadget/git/commit/afda36dbf3b4f5a489ab44c00d5210c1fa894a40
> >     seems to have introduced an issue for Zsh whereby __git_ps1 errs with
> >
> >     __git_ps1:96: = not found
> >
> >     when inside a repo. Changing == to = would seem to address for both Bash
> >     and Zsh.
> >
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-679%2Fdmalan%2Fpatch-1-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-679/dmalan/patch-1-v1
> > Pull-Request: https://github.com/gitgitgadget/git/pull/679
> >
> >  contrib/completion/git-prompt.sh | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> > index e6cd5464e5..16260bab73 100644
> > --- a/contrib/completion/git-prompt.sh
> > +++ b/contrib/completion/git-prompt.sh
> > @@ -433,7 +433,7 @@ __git_ps1 ()
> >       local sparse=""
> >       if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
> >          [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
> > -        [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
> > +        [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
> >               sparse="|SPARSE"
> >       fi
> >
> > @@ -542,7 +542,7 @@ __git_ps1 ()
> >               fi
> >
> >               if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
> > -                [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
> > +                [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
> >                       h="?"
> >               fi
> >
> >
> > base-commit: ae46588be0cd730430dded4491246dfb4eac5557
David J. Malan via GitGitGadget· Jul 21, 2020, 00:15 UTC · re: David J. Malan via GitGitGadget · lore

[PATCH v2] git-prompt: change == to = for zsh's sake

From: "David J. Malan" <malan@harvard.edu>

When using git-prompt.sh with zsh, __git_ps1 currently errs when inside a repo with:

__git_ps1:96: = not found

Avoid using non-portable "==" that is only understood by bash and not zsh. Change to "=" so that the prompt script becomes usable with zsh again.

Signed-off-by: David J. Malan <malan@harvard.edu>
---
    Change == to = for zsh's sake in git-prompt.sh
    
    Upon installing git-prompt.sh
    [https://github.com/gitgitgadget/git/blob/master/contrib/completion/git-prompt.sh] 
    on macOS Catalina, I noticed that 
    https://github.com/gitgitgadget/git/commit/afda36dbf3b4f5a489ab44c00d5210c1fa894a40 
    seems to have introduced an issue for Zsh whereby __git_ps1 errs with
    
    __git_ps1:96: = not found
    
    when inside a repo. Changing == to = would seem to address for both Bash
    and Zsh.
    
    Changes since v1:
    
     * Commit message rewritten to use imperative mood.
     * Commit message rewritten to elaborate on reason for change.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-679%2Fdmalan%2Fpatch-1-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-679/dmalan/patch-1-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/679
Range-diff vs v1:
 1:  95be513ed1 ! 1:  f5402f1512 git-prompt: changes == to = for zsh's sake
     @@ Metadata
      Author: David J. Malan <malan@harvard.edu>
      
       ## Commit message ##
     -    git-prompt: changes == to = for zsh's sake
     +    git-prompt: change == to = for zsh's sake
      
     -    When using git-prompt.sh with Zsh, __git_ps1 currently errs
     +    When using git-prompt.sh with zsh, __git_ps1 currently errs
          when inside a repo with:
      
          __git_ps1:96: = not found
      
     -    This commit changes `==` to `=` for both Bash and Zsh.
     +    Avoid using non-portable "==" that is only understood by bash
     +    and not zsh. Change to "=" so that the prompt script becomes
     +    usable with zsh again.
      
          Signed-off-by: David J. Malan <malan@harvard.edu>
      
 contrib/completion/git-prompt.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to contrib/completion/git-prompt.sh +2 −2
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index e6cd5464e5..16260bab73 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -433,7 +433,7 @@ __git_ps1 ()
 	local sparse=""
 	if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
 	   [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
-	   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
+	   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
 		sparse="|SPARSE"
 	fi
 
@@ -542,7 +542,7 @@ __git_ps1 ()
 		fi
 
 		if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
-		   [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
+		   [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
 			h="?"
 		fi
 

base-commit: ae46588be0cd730430dded4491246dfb4eac5557
-- 
gitgitgadget
Aaron Schrab· Jul 21, 2020, 00:23 UTC · re: David J. Malan via GitGitGadget · lore

Re: [PATCH] git-prompt: changes == to = for zsh's sake

At 23:17 +0000 20 Jul 2020, "David J. Malan via GitGitGadget" <gitgitgadget@gmail.com> wrote:
Show 6 quoted lines
>From: "David J. Malan" <malan@harvard.edu>
>
>When using git-prompt.sh with Zsh, __git_ps1 currently errs
>when inside a repo with:
>
>__git_ps1:96: = not found

That depends if zsh's `equals` option is set or not. If it's set (as it is by default) you'll get that behavior. If it's unset (`setopt no_equals`) that should behave as in bash. But, it fixing the code to work regardless of shell options is definitely a good thing.

>This commit changes `==` to `=` for both Bash and Zsh.

An alternate fix would be to switch to using double square brackets instead of single square brackets for the test. Since contents of double brackets have their own parsing rules the `equals` option doesn't apply there, and so `==` is available for checking equality same as in bash. IMHO, this provides saner behavior in general; although it's definitely not POSIX compliant.

Junio C Hamano· Jul 21, 2020, 00:40 UTC · re: Aaron Schrab · lore

Re: [PATCH] git-prompt: changes == to = for zsh's sake

Aaron Schrab <aaron@schrab.com> writes:
Show 6 quoted lines
> An alternate fix would be to switch to using double square brackets
> instead of single square brackets for the test. Since contents of
> double brackets have their own parsing rules the `equals` option
> doesn't apply there, and so `==` is available for checking equality
> same as in bash.  IMHO, this provides saner behavior in general;
> although it's definitely not POSIX compliant.

It won't be but it does not have to be POSIX compliant anyway; after all this is prompt support for bash with support for zsh added on the side, neither is limited to strict POSIX.

I'd say that the patch posted is good as-is.
Thanks.

← back to recent threads