# of values:
#
# verbose show number of commits ahead/behind (+/-) upstream
+# name if verbose, then also show the upstream abbrev name
# legacy don't use the '--count' option available in recent
# versions of git-rev-list
# git always compare HEAD to @{upstream}
{
local key value
local svn_remote svn_url_pattern count n
- local upstream=git legacy="" verbose=""
+ local upstream=git legacy="" verbose="" name=""
svn_remote=()
# get some config options from git-config
git|svn) upstream="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
+ name) name=1 ;;
esac
done
*) # diverged from upstream
p=" u+${count#* }-${count% *}" ;;
esac
+ if [[ -n "$count" && -n "$name" ]]; then
+ p="$p $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)"
+ fi
fi
}
r="$c_clear$r"
}
+eread ()
+{
+ local 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)
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"
+ eread "$g/rebase-merge/head-name" b
+ eread "$g/rebase-merge/msgnum" step
+ eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
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"
+ eread "$g/rebase-apply/next" step
+ eread "$g/rebase-apply/last" total
if [ -f "$g/rebase-apply/rebasing" ]; then
- read b 2>/dev/null <"$g/rebase-apply/head-name"
+ eread "$g/rebase-apply/head-name" b
r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
- if ! read head 2>/dev/null <"$g/HEAD"; then
+ if ! eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi