2d5412e99be6d9fab50169ad0cf290e022fc6e9b
- Author
- James Smith <james@loopj.com>
- Committer
- James Smith <james@loopj.com>
- Date
Message
Added new function git_remote_status to check if we are ahead, behind or diverged from the remote branch
Diff
1diff --git a/lib/git.zsh b/lib/git.zsh
2index 8512de8a40ba542e24d86be6e5c83c7245623875..75367f8777f475c32ebb9f77354ba51c36e1c452 100644
3--- a/lib/git.zsh
4+++ b/lib/git.zsh
5@@ -4,6 +4,7 @@ function git_prompt_info() {
6 echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
7 }
8
9+# get dirty status of the current working tree
10 parse_git_dirty () {
11 if [[ -n $(git status -s 2> /dev/null) ]]; then
12 echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
13@@ -12,6 +13,26 @@ parse_git_dirty () {
14 fi
15 }
16
17+# get the difference between the local and remote branches
18+git_remote_status() {
19+ remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
20+ if [[ -n ${remote} ]] ; then
21+ ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
22+ behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
23+
24+ if [ $ahead -eq 0 ] && [ $behind -gt 0 ]
25+ then
26+ echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
27+ elif [ $ahead -gt 0 ] && [ $behind -eq 0 ]
28+ then
29+ echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
30+ elif [ $ahead -gt 0 ] && [ $behind -gt 0 ]
31+ then
32+ echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
33+ fi
34+ fi
35+}
36+
37 # get the status of the working tree
38 git_prompt_status() {
39 INDEX=$(git status --porcelain 2> /dev/null)