From 1a2f72a28a55504532802e856654b7401fb63bcb Mon Sep 17 00:00:00 2001 From: Chris Djali Date: Thu, 27 Aug 2020 13:53:21 +0100 Subject: [PATCH] prompt: Avoid using unset variables 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 https://github.com/git-for-windows/git/issues/2799 Signed-off-by: Chris Djali Signed-off-by: Johannes Schindelin --- contrib/completion/git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 16260bab73346b..2d2fb00f97ee32 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -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 @@ -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