66
66
# git always compare HEAD to @{upstream}
67
67
# svn always compare HEAD to your SVN upstream
68
68
#
69
+ # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
70
+ # find one, or @{upstream} otherwise. Once you have set
71
+ # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
72
+ # setting the bash.showUpstream config variable.
73
+ #
69
74
# You can change the separator between the branch name and the above
70
75
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
71
76
# is SP.
79
84
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
80
85
# by setting GIT_PS1_OMITSPARSESTATE.
81
86
#
82
- # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
83
- # find one, or @{upstream} otherwise. Once you have set
84
- # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
85
- # setting the bash.showUpstream config variable.
86
- #
87
87
# If you would like to see more information about the identity of
88
88
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
89
89
# to one of these values:
@@ -115,7 +115,7 @@ __git_ps1_show_upstream ()
115
115
{
116
116
local key value
117
117
local svn_remote svn_url_pattern count n
118
- local upstream =git legacy=" " verbose=" " name=" "
118
+ local upstream_type =git legacy=" " verbose=" " name=" "
119
119
120
120
svn_remote=()
121
121
# get some config options from git-config
@@ -132,7 +132,7 @@ __git_ps1_show_upstream ()
132
132
svn-remote.* .url)
133
133
svn_remote[$(( ${# svn_remote[@]} + 1 )) ]=" $value "
134
134
svn_url_pattern=" $svn_url_pattern \\ |$value "
135
- upstream =svn+git # default upstream is SVN if available, else git
135
+ upstream_type =svn+git # default upstream type is SVN if available, else git
136
136
;;
137
137
esac
138
138
done <<< " $output"
@@ -141,16 +141,16 @@ __git_ps1_show_upstream ()
141
141
local option
142
142
for option in ${GIT_PS1_SHOWUPSTREAM} ; do
143
143
case " $option " in
144
- git|svn) upstream =" $option " ;;
144
+ git|svn) upstream_type =" $option " ;;
145
145
verbose) verbose=1 ;;
146
146
legacy) legacy=1 ;;
147
147
name) name=1 ;;
148
148
esac
149
149
done
150
150
151
- # Find our upstream
152
- case " $upstream " in
153
- git) upstream =" @{upstream}" ;;
151
+ # Find our upstream type
152
+ case " $upstream_type " in
153
+ git) upstream_type =" @{upstream}" ;;
154
154
svn* )
155
155
# get the upstream from the "git-svn-id: ..." in a commit message
156
156
# (git-svn uses essentially the same procedure internally)
@@ -167,24 +167,24 @@ __git_ps1_show_upstream ()
167
167
168
168
if [[ -z " $svn_upstream " ]]; then
169
169
# default branch name for checkouts with no layout:
170
- upstream =${GIT_SVN_ID:- git-svn}
170
+ upstream_type =${GIT_SVN_ID:- git-svn}
171
171
else
172
- upstream =${svn_upstream#/ }
172
+ upstream_type =${svn_upstream#/ }
173
173
fi
174
- elif [[ " svn+git" = " $upstream " ]]; then
175
- upstream =" @{upstream}"
174
+ elif [[ " svn+git" = " $upstream_type " ]]; then
175
+ upstream_type =" @{upstream}"
176
176
fi
177
177
;;
178
178
esac
179
179
180
180
# Find how many commits we are ahead/behind our upstream
181
181
if [[ -z " $legacy " ]]; then
182
182
count=" $( git rev-list --count --left-right \
183
- " $upstream " ...HEAD 2> /dev/null) "
183
+ " $upstream_type " ...HEAD 2> /dev/null) "
184
184
else
185
185
# produce equivalent output to --count for older versions of git
186
186
local commits
187
- if commits=" $( git rev-list --left-right " $upstream " ...HEAD 2> /dev/null) "
187
+ if commits=" $( git rev-list --left-right " $upstream_type " ...HEAD 2> /dev/null) "
188
188
then
189
189
local commit behind=0 ahead=0
190
190
for commit in $commits
@@ -214,26 +214,26 @@ __git_ps1_show_upstream ()
214
214
* ) # diverged from upstream
215
215
p=" <>" ;;
216
216
esac
217
- else
217
+ else # verbose, set upstream instead of p
218
218
case " $count " in
219
219
" " ) # no upstream
220
- p =" " ;;
220
+ upstream =" " ;;
221
221
" 0 0" ) # equal to upstream
222
- p= " u=" ;;
222
+ upstream= " | u=" ;;
223
223
" 0 " * ) # ahead of upstream
224
- p= " u+${count# 0 } " ;;
224
+ upstream= " | u+${count# 0 } " ;;
225
225
* " 0" ) # behind upstream
226
- p= " u-${count% 0} " ;;
226
+ upstream= " | u-${count% 0} " ;;
227
227
* ) # diverged from upstream
228
- p= " u+${count#* } -${count% * } " ;;
228
+ upstream= " | u+${count#* } -${count% * } " ;;
229
229
esac
230
230
if [[ -n " $count " && -n " $name " ]]; then
231
231
__git_ps1_upstream_name=$( git rev-parse \
232
- --abbrev-ref " $upstream " 2> /dev/null)
232
+ --abbrev-ref " $upstream_type " 2> /dev/null)
233
233
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
234
- p =" $p \$ {__git_ps1_upstream_name}"
234
+ upstream =" $upstream \$ {__git_ps1_upstream_name}"
235
235
else
236
- p =" $p ${__git_ps1_upstream_name} "
236
+ upstream =" $upstream ${__git_ps1_upstream_name} "
237
237
# not needed anymore; keep user's
238
238
# environment clean
239
239
unset __git_ps1_upstream_name
@@ -512,7 +512,8 @@ __git_ps1 ()
512
512
local u=" "
513
513
local h=" "
514
514
local c=" "
515
- local p=" "
515
+ local p=" " # short version of upstream state indicator
516
+ local upstream=" " # verbose version of upstream state indicator
516
517
517
518
if [ " true" = " $inside_gitdir " ]; then
518
519
if [ " true" = " $bare_repo " ]; then
@@ -568,8 +569,8 @@ __git_ps1 ()
568
569
b=" \$ {__git_ps1_branch_name}"
569
570
fi
570
571
571
- local f=" $h$w$i$s$u "
572
- local gitstring=" $c$b ${f: +$z$f }${sparse} $r$p "
572
+ local f=" $h$w$i$s$u$p "
573
+ local gitstring=" $c$b ${f: +$z$f }${sparse} $r ${upstream} "
573
574
574
575
if [ $pcmode = yes ]; then
575
576
if [ " ${__git_printf_supports_v-} " != yes ]; then
0 commit comments