Merge branch 'dk/maint-t5150-dirname'
[gitweb.git] / contrib / completion / git-prompt.sh
index 92f2770769799a8b9695788d95a521bb39a47dba..07a6218d10679f5102c3649794bfd98e1883da75 100644 (file)
@@ -125,7 +125,7 @@ __git_ps1_show_upstream ()
                        fi
                        ;;
                svn-remote.*.url)
-                       svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
+                       svn_remote[$((${#svn_remote[@]} + 1))]="$value"
                        svn_url_pattern+="\\|$value"
                        upstream=svn+git # default upstream is SVN if available, else git
                        ;;
@@ -147,10 +147,11 @@ __git_ps1_show_upstream ()
        svn*)
                # get the upstream from the "git-svn-id: ..." in a commit message
                # (git-svn uses essentially the same procedure internally)
-               local svn_upstream=($(git log --first-parent -1 \
+               local -a svn_upstream
+               svn_upstream=($(git log --first-parent -1 \
                                        --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
                if [[ 0 -ne ${#svn_upstream[@]} ]]; then
-                       svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
+                       svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
                        svn_upstream=${svn_upstream%@*}
                        local n_stop="${#svn_remote[@]}"
                        for ((n=1; n <= n_stop; n++)); do
@@ -346,9 +347,9 @@ __git_ps1 ()
                local step=""
                local total=""
                if [ -d "$g/rebase-merge" ]; then
-                       b="$(cat "$g/rebase-merge/head-name")"
-                       step=$(cat "$g/rebase-merge/msgnum")
-                       total=$(cat "$g/rebase-merge/end")
+                       b="$(cat "$g/rebase-merge/head-name" 2>/dev/null)"
+                       step=$(cat "$g/rebase-merge/msgnum" 2>/dev/null)
+                       total=$(cat "$g/rebase-merge/end" 2>/dev/null)
                        if [ -f "$g/rebase-merge/interactive" ]; then
                                r="|REBASE-i"
                        else
@@ -356,9 +357,10 @@ __git_ps1 ()
                        fi
                else
                        if [ -d "$g/rebase-apply" ]; then
-                               step=$(cat "$g/rebase-apply/next")
-                               total=$(cat "$g/rebase-apply/last")
+                               step=$(cat "$g/rebase-apply/next" 2>/dev/null)
+                               total=$(cat "$g/rebase-apply/last" 2>/dev/null)
                                if [ -f "$g/rebase-apply/rebasing" ]; then
+                                       b="$(cat "$g/rebase-apply/head-name" 2>/dev/null)"
                                        r="|REBASE"
                                elif [ -f "$g/rebase-apply/applying" ]; then
                                        r="|AM"
@@ -375,6 +377,7 @@ __git_ps1 ()
                                r="|BISECTING"
                        fi
 
+                       test -n "$b" ||
                        b="$(git symbolic-ref HEAD 2>/dev/null)" || {
                                detached=yes
                                b="$(