This repository was archived by the owner on Nov 9, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ _git_import_aliases () {
177177
178178# PROMPT =======================================================================
179179
180- PS1=' `_git_headname`!`_git_repo_state``_git_workdir``_git_dirty``_git_dirty_stash`> '
180+ PS1=' `_git_headname``_git_upstream_state` !`_git_repo_state``_git_workdir``_git_dirty``_git_dirty_stash`> '
181181
182182ANSI_RESET=" \001$( git config --get-color " " " reset" ) \002"
183183
@@ -215,6 +215,30 @@ _git_headname() {
215215 _git_apply_color " $br " " color.sh.branch" " yellow reverse"
216216}
217217
218+ # detect the deviation from the upstream branch
219+ _git_upstream_state () {
220+ local p=" "
221+
222+ # Find how many commits we are ahead/behind our upstream
223+ local count=" $( git rev-list --count --left-right " @{upstream}" ...HEAD 2> /dev/null) "
224+
225+ # calculate the result
226+ case " $count " in
227+ " " ) # no upstream
228+ p=" " ;;
229+ " 0 0" ) # equal to upstream
230+ p=" u=" ;;
231+ " 0 " * ) # ahead of upstream
232+ p=" u+${count# 0 } " ;;
233+ * " 0" ) # behind upstream
234+ p=" u-${count% 0} " ;;
235+ * ) # diverged from upstream
236+ p=" u+${count#* } -${count% * } " ;;
237+ esac
238+
239+ _git_apply_color " $p " " color.sh.upstream-state" " yellow bold"
240+ }
241+
218242# detect working directory relative to working tree root
219243_git_workdir () {
220244 subdir=` git rev-parse --show-prefix 2> /dev/null`
You can’t perform that action at this time.
0 commit comments