git-prompt.sh: localize `option` in __git_ps1_show_upstream
authorSibo Dong <redacted>
Sat, 31 Oct 2020 22:09:46 +0000 (22:09 +0000)
committerJunio C Hamano <redacted>
Mon, 2 Nov 2020 00:22:11 +0000 (16:22 -0800)
The variable 'option' is used in __git_ps1_show_upstream()
without being localized.

This clobbers the variable the user may be using for other
purposes, which is bad.  Luckily, $option is not used to carry
information around in the script as a global variable.  The use
of it in this script has very limited scope (namely, only inside
this function), so just declare that it is "local".

Signed-off-by: Sibo Dong <redacted>
Signed-off-by: Junio C Hamano <redacted>
contrib/completion/git-prompt.sh

index 16260bab73346ba79d8e96eda03628d7dbd4b75b..5116016d396ff637e53742240d0218e710ae66c9 100644 (file)
@@ -137,6 +137,7 @@ __git_ps1_show_upstream ()
        done <<< "$output"
 
        # parse configuration values
+       local option
        for option in ${GIT_PS1_SHOWUPSTREAM}; do
                case "$option" in
                git|svn) upstream="$option" ;;
git clone https://git.99rst.org/PROJECT