Merge branch 'bc/completion-for-bash-3.0' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2013 19:00:11 +0000 (12:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2013 19:00:11 +0000 (12:00 -0700)
Some people still use rather old versions of bash, which cannot grok
some constructs like 'printf -v varname' the prompt and completion
code started to use recently.

* bc/completion-for-bash-3.0:
contrib/git-prompt.sh: handle missing 'printf -v' more gracefully
t9902-completion.sh: old Bash still does not support array+=('') notation
git-completion.bash: use correct Bash/Zsh array length syntax

contrib/completion/git-completion.bash
contrib/completion/git-prompt.sh
t/t9902-completion.sh
index 5da920ecd9ec1b64760db863d266fdc9c47502de..e1b73130723a57e7f641236331699e67bb0d4d82 100644 (file)
@@ -2580,7 +2580,7 @@ if [[ -n ${ZSH_VERSION-} ]]; then
                                --*=*|*.) ;;
                                *) c="$c " ;;
                                esac
-                               array[$#array+1]="$c"
+                               array[${#array[@]}+1]="$c"
                        done
                        compset -P '*[=:]'
                        compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
index a81ef5a482d48b114a81e242109e2f0dec0839ed..d6c61b2bdecc5ca89e21ece5df7c2e4bbec9373c 100644 (file)
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
 
+# check whether printf supports -v
+__git_printf_supports_v=
+printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
+
 # stores the divergence from upstream in $p
 # used by GIT_PS1_SHOWUPSTREAM
 __git_ps1_show_upstream ()
@@ -433,7 +437,7 @@ __git_ps1 ()
        local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
 
        if [ $pcmode = yes ]; then
-               if [[ -n ${ZSH_VERSION-} ]]; then
+               if [ "${__git_printf_supports_v-}" != yes ]; then
                        gitstring=$(printf -- "$printf_format" "$gitstring")
                else
                        printf -v gitstring -- "$printf_format" "$gitstring"
index 272a071e85b0b7c6b34da06fd7492a257b09fa52..2d4beb5e50c257fed2f4b6475cb5834425b5a64f 100755 (executable)
@@ -69,7 +69,7 @@ run_completion ()
        local -a COMPREPLY _words
        local _cword
        _words=( $1 )
-       test "${1: -1}" = ' ' && _words+=('')
+       test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
        (( _cword = ${#_words[@]} - 1 ))
        __git_wrap__git_main && print_comp
 }