threads / patch / 55679

patchgit-prompt: work under set -u

Subject: [PATCH] git-prompt: work under set -u

## tl;dr

One message between May 13, 2021 and May 13, 2021. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Elijah Newren via GitGitGadget· May 13, 2021, 06:22 UTC · lore
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(-)
Show changes to contrib/completion/git-prompt.sh +3 −3
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

base-commit: df6c4f722c94641d5a9ea5496511f7043433abc2
-- 
gitgitgadget

← back to recent threads