Skip to content

Commit 0ec7c23

Browse files
justinrdonnellygitster
authored andcommitted
git-prompt: make upstream state indicator location consistent
Make upstream state indicator location more consistent with similar state indicators (e.g. sparse). Group the short upstream state indicator (`=`, `<`, `>`, or `<>`) with other short state indicators immediately after the branch name. Previously short and long upstream state indicators appeared after all other state indicators. Use a separator (`SP` or `GIT_PS1_STATESEPARATOR`) between branch name and short upstream state indicator. Previously the short upstream state indicator would sometimes appear directly adjacent to the branch name instead of being separated. For comparison, `__git_ps1` examples without upstream state indicator: (main) (main %) (main *%) (main|SPARSE) (main %|SPARSE) (main *%|SPARSE) (main|SPARSE|REBASE 1/2) (main %|SPARSE|REBASE 1/2) Note that if there are short state indicators, they appear together after the branch name and separated from it by `SP` or `GIT_PS1_STATESEPARATOR`. Before/after examples with short upstream state indicator: | Before | After | | ---------------- | ---------------- | | (main=) | (main =) | | (main|SPARSE=) | (main =|SPARSE) | | (main %|SPARSE=) | (main %=|SPARSE) | Signed-off-by: Justin Donnelly <[email protected]> Reviewed-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d9dc2c commit 0ec7c23

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

contrib/completion/git-prompt.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
__git_printf_supports_v=
110110
printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
111111

112-
# stores the divergence from upstream in $p
112+
# stores the divergence from upstream in $p (for short status) or $upstream (for verbose status)
113113
# used by GIT_PS1_SHOWUPSTREAM
114114
__git_ps1_show_upstream ()
115115
{
@@ -214,26 +214,26 @@ __git_ps1_show_upstream ()
214214
*) # diverged from upstream
215215
p="<>" ;;
216216
esac
217-
else
217+
else # verbose, set upstream instead of p
218218
case "$count" in
219219
"") # no upstream
220-
p="" ;;
220+
upstream="" ;;
221221
"0 0") # equal to upstream
222-
p=" u=" ;;
222+
upstream=" u=" ;;
223223
"0 "*) # ahead of upstream
224-
p=" u+${count#0 }" ;;
224+
upstream=" u+${count#0 }" ;;
225225
*" 0") # behind upstream
226-
p=" u-${count% 0}" ;;
226+
upstream=" u-${count% 0}" ;;
227227
*) # diverged from upstream
228-
p=" u+${count#* }-${count% *}" ;;
228+
upstream=" u+${count#* }-${count% *}" ;;
229229
esac
230230
if [[ -n "$count" && -n "$name" ]]; then
231231
__git_ps1_upstream_name=$(git rev-parse \
232232
--abbrev-ref "$upstream_type" 2>/dev/null)
233233
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
234-
p="$p \${__git_ps1_upstream_name}"
234+
upstream="$upstream \${__git_ps1_upstream_name}"
235235
else
236-
p="$p ${__git_ps1_upstream_name}"
236+
upstream="$upstream ${__git_ps1_upstream_name}"
237237
# not needed anymore; keep user's
238238
# environment clean
239239
unset __git_ps1_upstream_name
@@ -512,7 +512,8 @@ __git_ps1 ()
512512
local u=""
513513
local h=""
514514
local c=""
515-
local p=""
515+
local p="" # short version of upstream state indicator
516+
local upstream="" # verbose version of upstream state indicator
516517

517518
if [ "true" = "$inside_gitdir" ]; then
518519
if [ "true" = "$bare_repo" ]; then
@@ -568,8 +569,8 @@ __git_ps1 ()
568569
b="\${__git_ps1_branch_name}"
569570
fi
570571

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}"
573574

574575
if [ $pcmode = yes ]; then
575576
if [ "${__git_printf_supports_v-}" != yes ]; then

0 commit comments

Comments
 (0)