Merge branch 'jd/prompt-upstream-mark'
Tweaks in the command line prompt (in contrib/) code around its GIT_PS1_SHOWUPSTREAM feature. * jd/prompt-upstream-mark: git-prompt: put upstream comments together git-prompt: make long upstream state indicator consistent git-prompt: make upstream state indicator location consistent git-prompt: rename `upstream` to `upstream_type`
This commit is contained in:
@ -66,6 +66,11 @@
|
|||||||
# git always compare HEAD to @{upstream}
|
# git always compare HEAD to @{upstream}
|
||||||
# svn always compare HEAD to your SVN upstream
|
# svn always compare HEAD to your SVN upstream
|
||||||
#
|
#
|
||||||
|
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
|
||||||
|
# find one, or @{upstream} otherwise. Once you have set
|
||||||
|
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
|
||||||
|
# setting the bash.showUpstream config variable.
|
||||||
|
#
|
||||||
# You can change the separator between the branch name and the above
|
# You can change the separator between the branch name and the above
|
||||||
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
|
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
|
||||||
# is SP.
|
# is SP.
|
||||||
@ -79,11 +84,6 @@
|
|||||||
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
|
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
|
||||||
# by setting GIT_PS1_OMITSPARSESTATE.
|
# by setting GIT_PS1_OMITSPARSESTATE.
|
||||||
#
|
#
|
||||||
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
|
|
||||||
# find one, or @{upstream} otherwise. Once you have set
|
|
||||||
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
|
|
||||||
# setting the bash.showUpstream config variable.
|
|
||||||
#
|
|
||||||
# If you would like to see more information about the identity of
|
# If you would like to see more information about the identity of
|
||||||
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
|
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
|
||||||
# to one of these values:
|
# to one of these values:
|
||||||
@ -115,7 +115,7 @@ __git_ps1_show_upstream ()
|
|||||||
{
|
{
|
||||||
local key value
|
local key value
|
||||||
local svn_remote svn_url_pattern count n
|
local svn_remote svn_url_pattern count n
|
||||||
local upstream=git legacy="" verbose="" name=""
|
local upstream_type=git legacy="" verbose="" name=""
|
||||||
|
|
||||||
svn_remote=()
|
svn_remote=()
|
||||||
# get some config options from git-config
|
# get some config options from git-config
|
||||||
@ -132,7 +132,7 @@ __git_ps1_show_upstream ()
|
|||||||
svn-remote.*.url)
|
svn-remote.*.url)
|
||||||
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
|
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
|
||||||
svn_url_pattern="$svn_url_pattern\\|$value"
|
svn_url_pattern="$svn_url_pattern\\|$value"
|
||||||
upstream=svn+git # default upstream is SVN if available, else git
|
upstream_type=svn+git # default upstream type is SVN if available, else git
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done <<< "$output"
|
done <<< "$output"
|
||||||
@ -141,16 +141,16 @@ __git_ps1_show_upstream ()
|
|||||||
local option
|
local option
|
||||||
for option in ${GIT_PS1_SHOWUPSTREAM}; do
|
for option in ${GIT_PS1_SHOWUPSTREAM}; do
|
||||||
case "$option" in
|
case "$option" in
|
||||||
git|svn) upstream="$option" ;;
|
git|svn) upstream_type="$option" ;;
|
||||||
verbose) verbose=1 ;;
|
verbose) verbose=1 ;;
|
||||||
legacy) legacy=1 ;;
|
legacy) legacy=1 ;;
|
||||||
name) name=1 ;;
|
name) name=1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Find our upstream
|
# Find our upstream type
|
||||||
case "$upstream" in
|
case "$upstream_type" in
|
||||||
git) upstream="@{upstream}" ;;
|
git) upstream_type="@{upstream}" ;;
|
||||||
svn*)
|
svn*)
|
||||||
# get the upstream from the "git-svn-id: ..." in a commit message
|
# get the upstream from the "git-svn-id: ..." in a commit message
|
||||||
# (git-svn uses essentially the same procedure internally)
|
# (git-svn uses essentially the same procedure internally)
|
||||||
@ -167,12 +167,12 @@ __git_ps1_show_upstream ()
|
|||||||
|
|
||||||
if [[ -z "$svn_upstream" ]]; then
|
if [[ -z "$svn_upstream" ]]; then
|
||||||
# default branch name for checkouts with no layout:
|
# default branch name for checkouts with no layout:
|
||||||
upstream=${GIT_SVN_ID:-git-svn}
|
upstream_type=${GIT_SVN_ID:-git-svn}
|
||||||
else
|
else
|
||||||
upstream=${svn_upstream#/}
|
upstream_type=${svn_upstream#/}
|
||||||
fi
|
fi
|
||||||
elif [[ "svn+git" = "$upstream" ]]; then
|
elif [[ "svn+git" = "$upstream_type" ]]; then
|
||||||
upstream="@{upstream}"
|
upstream_type="@{upstream}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -180,11 +180,11 @@ __git_ps1_show_upstream ()
|
|||||||
# Find how many commits we are ahead/behind our upstream
|
# Find how many commits we are ahead/behind our upstream
|
||||||
if [[ -z "$legacy" ]]; then
|
if [[ -z "$legacy" ]]; then
|
||||||
count="$(git rev-list --count --left-right \
|
count="$(git rev-list --count --left-right \
|
||||||
"$upstream"...HEAD 2>/dev/null)"
|
"$upstream_type"...HEAD 2>/dev/null)"
|
||||||
else
|
else
|
||||||
# produce equivalent output to --count for older versions of git
|
# produce equivalent output to --count for older versions of git
|
||||||
local commits
|
local commits
|
||||||
if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
|
if commits="$(git rev-list --left-right "$upstream_type"...HEAD 2>/dev/null)"
|
||||||
then
|
then
|
||||||
local commit behind=0 ahead=0
|
local commit behind=0 ahead=0
|
||||||
for commit in $commits
|
for commit in $commits
|
||||||
@ -214,26 +214,26 @@ __git_ps1_show_upstream ()
|
|||||||
*) # diverged from upstream
|
*) # diverged from upstream
|
||||||
p="<>" ;;
|
p="<>" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else # verbose, set upstream instead of p
|
||||||
case "$count" in
|
case "$count" in
|
||||||
"") # no upstream
|
"") # no upstream
|
||||||
p="" ;;
|
upstream="" ;;
|
||||||
"0 0") # equal to upstream
|
"0 0") # equal to upstream
|
||||||
p=" u=" ;;
|
upstream="|u=" ;;
|
||||||
"0 "*) # ahead of upstream
|
"0 "*) # ahead of upstream
|
||||||
p=" u+${count#0 }" ;;
|
upstream="|u+${count#0 }" ;;
|
||||||
*" 0") # behind upstream
|
*" 0") # behind upstream
|
||||||
p=" u-${count% 0}" ;;
|
upstream="|u-${count% 0}" ;;
|
||||||
*) # diverged from upstream
|
*) # diverged from upstream
|
||||||
p=" u+${count#* }-${count% *}" ;;
|
upstream="|u+${count#* }-${count% *}" ;;
|
||||||
esac
|
esac
|
||||||
if [[ -n "$count" && -n "$name" ]]; then
|
if [[ -n "$count" && -n "$name" ]]; then
|
||||||
__git_ps1_upstream_name=$(git rev-parse \
|
__git_ps1_upstream_name=$(git rev-parse \
|
||||||
--abbrev-ref "$upstream" 2>/dev/null)
|
--abbrev-ref "$upstream_type" 2>/dev/null)
|
||||||
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
||||||
p="$p \${__git_ps1_upstream_name}"
|
upstream="$upstream \${__git_ps1_upstream_name}"
|
||||||
else
|
else
|
||||||
p="$p ${__git_ps1_upstream_name}"
|
upstream="$upstream ${__git_ps1_upstream_name}"
|
||||||
# not needed anymore; keep user's
|
# not needed anymore; keep user's
|
||||||
# environment clean
|
# environment clean
|
||||||
unset __git_ps1_upstream_name
|
unset __git_ps1_upstream_name
|
||||||
@ -512,7 +512,8 @@ __git_ps1 ()
|
|||||||
local u=""
|
local u=""
|
||||||
local h=""
|
local h=""
|
||||||
local c=""
|
local c=""
|
||||||
local p=""
|
local p="" # short version of upstream state indicator
|
||||||
|
local upstream="" # verbose version of upstream state indicator
|
||||||
|
|
||||||
if [ "true" = "$inside_gitdir" ]; then
|
if [ "true" = "$inside_gitdir" ]; then
|
||||||
if [ "true" = "$bare_repo" ]; then
|
if [ "true" = "$bare_repo" ]; then
|
||||||
@ -568,8 +569,8 @@ __git_ps1 ()
|
|||||||
b="\${__git_ps1_branch_name}"
|
b="\${__git_ps1_branch_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local f="$h$w$i$s$u"
|
local f="$h$w$i$s$u$p"
|
||||||
local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
|
local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"
|
||||||
|
|
||||||
if [ $pcmode = yes ]; then
|
if [ $pcmode = yes ]; then
|
||||||
if [ "${__git_printf_supports_v-}" != yes ]; then
|
if [ "${__git_printf_supports_v-}" != yes ]; then
|
||||||
|
Reference in New Issue
Block a user