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>
  • Loading branch information
AnyOldName3 authored and Git for Windows Build Agent committed Oct 8, 2020
1 parent 6e8084b commit 0077689
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 @@ -431,8 +431,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 @@ -541,7 +541,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 0077689

Please sign in to comment.