git-prompt.sh: Don't error on null ${ZSH,BASH}_VERSION, $short_sha
When the shell is in "nounset" or "set -u" mode, referencing unset or null variables results in an error. Protect $ZSH_VERSION and $BASH_VERSION against that, and initialize $short_sha before use. Signed-off-by: Ville Skyttä <ville.skytta@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ville Skyttä committed
Jun 6, 2016 at 19:29 UTC
34d8f5a8aa4aa17af3158f325173eb08c9c05eb1
1 file changed
+3
-3
contrib/completion/git-prompt.sh
+3
-3
@@ -355,8 +355,8 @@ __git_ps1 ()
355
# incorrect.)
356
#
357
local ps1_expanded=yes
358
- [ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
359
- [ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
358
+ [ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
359
+ [ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
360
361
local repo_info rev_parse_exit_code
362
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
@@ -368,7 +368,7 @@ __git_ps1 ()
368
return $exit
369
fi
370
371
- local short_sha
371
+ local short_sha=""
372
if [ "$rev_parse_exit_code" = "0" ]; then
373
short_sha="${repo_info##*$'\n'}"
374
repo_info="${repo_info%$'\n'*}"