Skip to content

Commit 8bf6d82

Browse files
AnyOldName3Git for Windows Build Agent
authored and
Git for Windows Build Agent
committed
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 #2799 Signed-off-by: Chris Djali <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 60b4583 commit 8bf6d82

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

contrib/completion/git-prompt.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ __git_ps1 ()
433433
fi
434434

435435
local sparse=""
436-
if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
437-
[ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
436+
if [ -z "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
437+
[ -z "${GIT_PS1_OMITSPARSESTATE-}" ] &&
438438
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
439439
sparse="|SPARSE"
440440
fi
@@ -548,7 +548,7 @@ __git_ps1 ()
548548
u="%${ZSH_VERSION+%}"
549549
fi
550550

551-
if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
551+
if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
552552
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
553553
h="?"
554554
fi

0 commit comments

Comments
 (0)