Skip to content

Commit 807c895

Browse files
committed
Merge branch 'jc/prompt-upstream'
An enhancement to the GIT_PS1_SHOWUPSTREAM facility. * jc/prompt-upstream: git-prompt.sh: optionally show upstream branch name
2 parents f2c1b01 + 1f6806c commit 807c895

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

contrib/completion/git-prompt.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
# of values:
6161
#
6262
# verbose show number of commits ahead/behind (+/-) upstream
63+
# name if verbose, then also show the upstream abbrev name
6364
# legacy don't use the '--count' option available in recent
6465
# versions of git-rev-list
6566
# git always compare HEAD to @{upstream}
@@ -94,7 +95,7 @@ __git_ps1_show_upstream ()
9495
{
9596
local key value
9697
local svn_remote svn_url_pattern count n
97-
local upstream=git legacy="" verbose=""
98+
local upstream=git legacy="" verbose="" name=""
9899

99100
svn_remote=()
100101
# get some config options from git-config
@@ -122,6 +123,7 @@ __git_ps1_show_upstream ()
122123
git|svn) upstream="$option" ;;
123124
verbose) verbose=1 ;;
124125
legacy) legacy=1 ;;
126+
name) name=1 ;;
125127
esac
126128
done
127129

@@ -204,6 +206,9 @@ __git_ps1_show_upstream ()
204206
*) # diverged from upstream
205207
p=" u+${count#* }-${count% *}" ;;
206208
esac
209+
if [[ -n "$count" && -n "$name" ]]; then
210+
p="$p $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)"
211+
fi
207212
fi
208213

209214
}

0 commit comments

Comments
 (0)