git prompt: use toplevel to find untracked files
[gitweb.git] / contrib / completion / git-prompt.sh
index e7ae736e4b6f7585e3d89960f8ff67455da81401..10c4d0ad74bc072afc86440c8810e2c3faae00ba 100644 (file)
@@ -268,6 +268,13 @@ __git_ps1_colorize_gitstring ()
        r="$c_clear$r"
 }
 
+__git_eread ()
+{
+       f="$1"
+       shift
+       test -r "$f" && read "$@" <"$f"
+}
+
 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
 # when called from PS1 using command substitution
 # in this mode it prints text to add to bash PS1 prompt (includes branch name)
@@ -367,9 +374,9 @@ __git_ps1 ()
        local step=""
        local total=""
        if [ -d "$g/rebase-merge" ]; then
-               read b 2>/dev/null <"$g/rebase-merge/head-name"
-               read step 2>/dev/null <"$g/rebase-merge/msgnum"
-               read total 2>/dev/null <"$g/rebase-merge/end"
+               __git_eread "$g/rebase-merge/head-name" b
+               __git_eread "$g/rebase-merge/msgnum" step
+               __git_eread "$g/rebase-merge/end" total
                if [ -f "$g/rebase-merge/interactive" ]; then
                        r="|REBASE-i"
                else
@@ -377,10 +384,10 @@ __git_ps1 ()
                fi
        else
                if [ -d "$g/rebase-apply" ]; then
-                       read step 2>/dev/null <"$g/rebase-apply/next"
-                       read total 2>/dev/null <"$g/rebase-apply/last"
+                       __git_eread "$g/rebase-apply/next" step
+                       __git_eread "$g/rebase-apply/last" total
                        if [ -f "$g/rebase-apply/rebasing" ]; then
-                               read b 2>/dev/null <"$g/rebase-apply/head-name"
+                               __git_eread "$g/rebase-apply/head-name" b
                                r="|REBASE"
                        elif [ -f "$g/rebase-apply/applying" ]; then
                                r="|AM"
@@ -404,7 +411,7 @@ __git_ps1 ()
                        b="$(git symbolic-ref HEAD 2>/dev/null)"
                else
                        local head=""
-                       if ! read head 2>/dev/null <"$g/HEAD"; then
+                       if ! __git_eread "$g/HEAD" head; then
                                if [ $pcmode = yes ]; then
                                        PS1="$ps1pc_start$ps1pc_end"
                                fi
@@ -467,7 +474,7 @@ __git_ps1 ()
 
                if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
                   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
-                  git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
+                  git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
                then
                        u="%${ZSH_VERSION+%}"
                fi