Subject: Re: [PATCH] git-prompt.sh: don't assume the shell expands the value of PS1

From: Junio C Hamano <[email-masked]>
Date: Tue, 20 May 2014 11:38:17 -0700

Richard Hansen <[email-masked]> writes:

> Not all shells subject the prompt string to parameter expansion.  Test
> whether the shell will expand the value of PS1, and use the result to
> control whether raw ref names are included directly in PS1.
>
> This fixes a regression introduced in commit 8976500 ("git-prompt.sh:
> don't put unsanitized branch names in $PS1"):  zsh does not expand PS1
> by default, but that commit assumed it did.  The bug resulted in
> prompts containing the literal string '${__git_ps1_branch_name}'
> instead of the actual branch name.
>
> Reported-by: Caleb Thompson <[email-masked]>
> Signed-off-by: Richard Hansen <[email-masked]>
> ---

Thanks, applied.

> To prevent a regression like this from happening again, I plan on
> adding new zsh test cases and expanding the bash test cases (to test
> the behavior with 'shopt -u promptvars').  I'd like the zsh tests to
> cover the same stuff as the bash tests.  These are the steps I am
> considering:
>
>   1. delete the last test case in t9903 ("prompt - zsh color pc mode")
>   2. add two new functions to t/lib-bash.sh:
>          ps1_expansion_enable () { shopt -s promptvars; }
>          ps1_expansion_disable () { shopt -u promptvars; }
>   3. loop over the relevant test cases twice:  once after calling
>      ps1_expansion_enable and once after calling ps1_expansion_disable
>      (with appropriate adjustments to the expected output)
>   4. move the test cases in t9903 to a separate library file and
>      source it from t9903-bash-prompt.sh
>   5. create two new files:
>        * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)
>        * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but
>          tweaked for zsh)
>
> Does this approach sound reasonable?

Sounds like a plan, especially if step 4 does a reasonable job of
factoring out as much common stuff as possible.