f9e133b88a9460252839eb7d7a7fc11a6a45009f

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

gitfast: fix error in git-prompt.sh (#8132)

An error was thrown (`bash: [: =: unary operator expected`) when using the __git_ps1_colorize_gitstring function outside of the one place it's called (line 512), because the "detached" variable was not quoted, and was unset.

Diff

 1diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
 2index fd2b049dbde3cd6b1a2583e7c32f3ea2915052be..f7009b063342d940c0e1dfce6b2207f46373330b 100644
 3--- a/plugins/gitfast/git-prompt.sh
 4+++ b/plugins/gitfast/git-prompt.sh
 5@@ -219,7 +219,7 @@ __git_ps1_show_upstream ()
 6 		if [[ -n "$count" && -n "$name" ]]; then
 7 			__git_ps1_upstream_name=$(git rev-parse \
 8 				--abbrev-ref "$upstream" 2>/dev/null)
 9-			if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
10+			if [ "$pcmode" = yes ] && [ "$ps1_expanded" = yes ]; then
11 				p="$p \${__git_ps1_upstream_name}"
12 			else
13 				p="$p ${__git_ps1_upstream_name}"
14@@ -237,7 +237,7 @@ __git_ps1_show_upstream ()
15 # to build a gitstring.
16 __git_ps1_colorize_gitstring ()
17 {
18-	if [[ -n ${ZSH_VERSION-} ]]; then
19+	if [[ -n "${ZSH_VERSION-}" ]]; then
20 		local c_red='%F{red}'
21 		local c_green='%F{green}'
22 		local c_lblue='%F{blue}'
23@@ -255,7 +255,7 @@ __git_ps1_colorize_gitstring ()
24 	local flags_color="$c_lblue"
25 
26 	local branch_color=""
27-	if [ $detached = no ]; then
28+	if [ "$detached" = no ]; then
29 		branch_color="$ok_color"
30 	else
31 		branch_color="$bad_color"
32@@ -508,13 +508,13 @@ __git_ps1 ()
33 
34 	# NO color option unless in PROMPT_COMMAND mode or it's Zsh
35 	if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
36-		if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
37+		if [ "$pcmode" = yes ] || [ -n "${ZSH_VERSION-}" ]; then
38 			__git_ps1_colorize_gitstring
39 		fi
40 	fi
41 
42 	b=${b##refs/heads/}
43-	if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
44+	if [ "$pcmode" = yes ] && [ "$ps1_expanded" = yes ]; then
45 		__git_ps1_branch_name=$b
46 		b="\${__git_ps1_branch_name}"
47 	fi
48@@ -522,7 +522,7 @@ __git_ps1 ()
49 	local f="$w$i$s$u"
50 	local gitstring="$c$b${f:+$z$f}$r$p"
51 
52-	if [ $pcmode = yes ]; then
53+	if [ "$pcmode" = yes ]; then
54 		if [ "${__git_printf_supports_v-}" != yes ]; then
55 			gitstring=$(printf -- "$printf_format" "$gitstring")
56 		else