{"thread":{"id":"42540","subject":"[PATCH 1/2] git-prompt.sh: Don't error on null ${ZSH,BASH}_VERSION, $short_sha","startedAt":"2016-06-06T16:29:33Z","lastAt":"2016-06-07T05:22:04Z","messageCount":3,"participants":["Ville Skyttä","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"288449","messageId":"1465230573-18357-1-git-send-email-ville.skytta@iki.fi","threadId":"42540","inReplyTo":null,"subject":"[PATCH 1/2] git-prompt.sh: Don't error on null ${ZSH,BASH}_VERSION, $short_sha","fromName":"Ville Skyttä","fromEmail":"ville.skytta@iki.fi","sentAt":"2016-06-06T16:29:33Z","receivedAt":"2016-06-06T16:29:33Z","isPatch":true,"sender":{"key":"ville.skytta@iki.fi","avatar":"https://avatars.githubusercontent.com/u/109152?v=4"},"body":"When the shell is in \"nounset\" or \"set -u\" mode, referencing unset or\nnull variables results in an error. Protect $ZSH_VERSION and\n$BASH_VERSION against that, and initialize $short_sha before use.\n\nSigned-off-by: Ville Skyttä <ville.skytta@iki.fi>\n---\n contrib/completion/git-prompt.sh | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 64219e6..97eacd7 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -355,8 +355,8 @@ __git_ps1 ()\n \t# incorrect.)\n \t#\n \tlocal ps1_expanded=yes\n-\t[ -z \"$ZSH_VERSION\" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no\n-\t[ -z \"$BASH_VERSION\" ] || shopt -q promptvars || ps1_expanded=no\n+\t[ -z \"${ZSH_VERSION-}\" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no\n+\t[ -z \"${BASH_VERSION-}\" ] || shopt -q promptvars || ps1_expanded=no\n \n \tlocal repo_info rev_parse_exit_code\n \trepo_info=\"$(git rev-parse --git-dir --is-inside-git-dir \\\n@@ -368,7 +368,7 @@ __git_ps1 ()\n \t\treturn $exit\n \tfi\n \n-\tlocal short_sha\n+\tlocal short_sha=\"\"\n \tif [ \"$rev_parse_exit_code\" = \"0\" ]; then\n \t\tshort_sha=\"${repo_info##*$'\\n'}\"\n \t\trepo_info=\"${repo_info%$'\\n'*}\"\n-- \n2.5.5\n"},{"id":"288482","messageId":"xmqq37oqw05b.fsf@gitster.mtv.corp.google.com","threadId":"42540","inReplyTo":"1465230573-18357-1-git-send-email-ville.skytta@iki.fi","subject":"Re: [PATCH 1/2] git-prompt.sh: Don't error on null ${ZSH,BASH}_VERSION, $short_sha","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-06T20:08:32Z","receivedAt":"2016-06-06T20:08:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ville Skyttä <ville.skytta@iki.fi> writes:\n\n> When the shell is in \"nounset\" or \"set -u\" mode, referencing unset or\n> null variables results in an error. Protect $ZSH_VERSION and\n> $BASH_VERSION against that, and initialize $short_sha before use.\n>\n> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>\n> ---\n\nThanks for following up.  I do not run my interactive shells with\n\"set -u\", so I never noticed these, but apparently you do (or you\nknow who does)--does this patch cover everything that is not \"-u\"\nsafe?\n\nWill queue.\n\n>  contrib/completion/git-prompt.sh | 6 +++---\n>  1 file changed, 3 insertions(+), 3 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 64219e6..97eacd7 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -355,8 +355,8 @@ __git_ps1 ()\n>  \t# incorrect.)\n>  \t#\n>  \tlocal ps1_expanded=yes\n> -\t[ -z \"$ZSH_VERSION\" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no\n> -\t[ -z \"$BASH_VERSION\" ] || shopt -q promptvars || ps1_expanded=no\n> +\t[ -z \"${ZSH_VERSION-}\" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no\n> +\t[ -z \"${BASH_VERSION-}\" ] || shopt -q promptvars || ps1_expanded=no\n>  \n>  \tlocal repo_info rev_parse_exit_code\n>  \trepo_info=\"$(git rev-parse --git-dir --is-inside-git-dir \\\n> @@ -368,7 +368,7 @@ __git_ps1 ()\n>  \t\treturn $exit\n>  \tfi\n>  \n> -\tlocal short_sha\n> +\tlocal short_sha=\"\"\n>  \tif [ \"$rev_parse_exit_code\" = \"0\" ]; then\n>  \t\tshort_sha=\"${repo_info##*$'\\n'}\"\n>  \t\trepo_info=\"${repo_info%$'\\n'*}\"\n"},{"id":"288516","messageId":"CABr9L5Bntn1+FGks6DfeJ6QMRr4CSHWwn8ggNGWroXe1kWczXQ@mail.gmail.com","threadId":"42540","inReplyTo":"xmqq37oqw05b.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 1/2] git-prompt.sh: Don't error on null ${ZSH,BASH}_VERSION, $short_sha","fromName":"Ville Skyttä","fromEmail":"ville.skytta@iki.fi","sentAt":"2016-06-07T05:22:04Z","receivedAt":"2016-06-07T05:22:04Z","isPatch":true,"sender":{"key":"ville.skytta@iki.fi","avatar":"https://avatars.githubusercontent.com/u/109152?v=4"},"body":"On Mon, Jun 6, 2016 at 11:08 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ville Skyttä <ville.skytta@iki.fi> writes:\n>\n>> When the shell is in \"nounset\" or \"set -u\" mode, referencing unset or\n>> null variables results in an error. Protect $ZSH_VERSION and\n>> $BASH_VERSION against that, and initialize $short_sha before use.\n>>\n>> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>\n>> ---\n>\n> Thanks for following up.  I do not run my interactive shells with\n> \"set -u\", so I never noticed these, but apparently you do (or you\n> know who does)\n\nI don't personally, but some do. The issue pops up every now and then\nwith bash-completion, e.g.\nhttps://github.com/scop/bash-completion/issues/44\n\n> does this patch cover everything that is not \"-u\" safe?\n\nI don't know. These were the low hanging fruits I've come across. Null\n$ZSH_VERSION in git-prompt.sh was the thing I ran into immediately\nwhen enabling \"nounset\" mode to start looking into the above\nbash-completion issue. Quick testing with zsh revealed the same issue\nwith null $BASH_VERSION, and you found the $short_sha one.\n"}]}