Skip to content

Commit

Permalink
prompt: Avoid using unset variables
Browse files Browse the repository at this point in the history
After `set -u` in Bash, the Git prompt would not be displayed and the
error `bash: GIT_PS1_COMPRESSSPARSESTATE: unbound variable` would be
printed, due to `GIT_PS1_COMPRESSSPARSESTATE` being unset by default
when it gets used.

This change sets a default value of an empty string to use when the
variable is unset to explicitly make the behaviour consistent between
`set -u` and `set +u`.

This fixes #2799

Signed-off-by: Chris Djali <krizdjali+github@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
AnyOldName3 authored and Git for Windows Build Agent committed May 14, 2021
1 parent 6a04a1f commit 6b3c479
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6b3c479

Please sign in to comment.