diff mbox series

git-prompt: work under set -u

Message ID pull.1024.git.git.1620886957441.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit 4467131ca3d965c3c24779bf58f98e0f53896598
Headers show
Series git-prompt: work under set -u | expand

Commit Message

Elijah Newren May 13, 2021, 6:22 a.m. UTC
From: Elijah Newren <newren@gmail.com>

Commit afda36dbf3 ("git-prompt: include sparsity state as well",
2020-06-21) added the use of some variables to control how to show
sparsity state in the git prompt, but implicitly assumed that undefined
variables would be treated as the empty string.  This breaks users who
run under 'set -u'; fix the code to be more explicit.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    git-prompt: work under set -u

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1024%2Fnewren%2Ffix-git-prompt-under-set-u-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1024/newren/fix-git-prompt-under-set-u-v1
Pull-Request: https://github.com/git/git/pull/1024

 contrib/completion/git-prompt.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: df6c4f722c94641d5a9ea5496511f7043433abc2
diff mbox series

Patch

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 4640a1535d15..db7c0068fb55 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -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