Re: git-sh-prompt: bash: GIT_PS1_COMPRESSSPARSESTATE: unbound variable
- From
Elijah Newren <newren@gmail.com>
- Date
- May 13, 2021, 04:53 UTC
- Message-ID
- <CABPp-BGERNLKbLA_r7i7+r+v7YK6xT00_5n9ebESb2SzLhC0Cg@mail.gmail.com>
- In-Reply-To
- <xmqqzgwzb7ad.fsf@gitster.g>
On Wed, May 12, 2021 at 9:13 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 34 quoted lines
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Christoph Anton Mitterer <calestyo@scientia.net> writes:
> >
> >> Could it be that git-sh-prompt no longer works properly?
> >>
> >> With git 2.31.1:
> >> $ . /usr/lib/git-core/git-sh-prompt
> >> $ PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
> >> $ cd someGitRepo
> >> bash: GIT_PS1_COMPRESSSPARSESTATE: unbound variable
> >> $
> >
> > Would
> >
> > $ set +u
> >
> > fix it, I have to wonder?
>
> Assuming that the answer is yes,...
>
> I do not know who maintains this contrib/ script, but here is what
>
> $ git grep -e '\$GIT_PS1_' -e '\${GIT_PS1_[^}-]*}' contrib/completion
>
> gave me a handful candidates for fixes. Randomly picking Elijah from
> the output of
>
> $ git shortlog --no-merges -sn --since=18.months \
> contrib/completion/git-prompt.sh |
> head -n 1
>
> for ideas.Yeah, I accidentally was relying on undefined-translates-to-empty, which breaks under set -u. I can duplicate the precise error, and your fix below is exactly how I fixed it too, before seeing you posted the same fix.
I'll post a patch with you as author...and some questions on what to do with the rest of the commit message and attribution tags.
Show 38 quoted lines
> Thanks.
>
> contrib/completion/git-prompt.sh | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git i/contrib/completion/git-prompt.sh w/contrib/completion/git-prompt.sh
> index 4640a1535d..b9485f4016 100644
> --- i/contrib/completion/git-prompt.sh
> +++ w/contrib/completion/git-prompt.sh
> @@ -139,7 +139,7 @@ __git_ps1_show_upstream ()
>
> # parse configuration values
> local option
> - for option in ${GIT_PS1_SHOWUPSTREAM}; do
> + for option in ${GIT_PS1_SHOWUPSTREAM-}; do
> case "$option" in
> git|svn) upstream="$option" ;;
> verbose) verbose=1 ;;
> @@ -433,8 +433,8 @@ __git_ps1 ()
> fi
>
> local sparse=""
> - if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
> - [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
> + if [ -z "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
> + [ -z "${GIT_PS1_OMITSPARSESTATE-}" ] &&
> [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
> sparse="|SPARSE"
> fi
> @@ -543,7 +543,7 @@ __git_ps1 ()
> u="%${ZSH_VERSION+%}"
> fi
>
> - if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
> + if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
> [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
> h="?"
> fi