From 3c485db8c73bfebf379f3e9382eb8f300b608bd8 Mon Sep 17 00:00:00 2001 From: r3dDoX Date: Sat, 24 May 2014 12:15:26 +0200 Subject: [PATCH 1/3] replaced hardcoded origin/{branch-name} with @{upstream} which gets the upstream branch since git 1.7.0 --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 305a77af..3eca8a6c 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -54,7 +54,7 @@ git_remote_status() { # Checks if there are commits ahead from remote function git_prompt_ahead() { - if $(echo "$(command git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then echo "$ZSH_THEME_GIT_PROMPT_AHEAD" fi } From 59c8fcc712556a4c0b612898073e212877c21d60 Mon Sep 17 00:00:00 2001 From: r3dDoX Date: Sat, 24 May 2014 12:19:46 +0200 Subject: [PATCH 2/3] added new function to get number of commits ahead of remote --- lib/git.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index 3eca8a6c..d6cee37c 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -59,6 +59,13 @@ function git_prompt_ahead() { fi } +# Gets the number of commits ahead from remote +function git_commits_ahead() { + if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + echo "$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')" + fi +} + # Formats prompt string for current git commit short SHA function git_prompt_short_sha() { SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" From 514693125b12d4b4cd099dcb09174f7bfd9a5b0e Mon Sep 17 00:00:00 2001 From: r3dDoX Date: Mon, 26 May 2014 10:47:51 +0200 Subject: [PATCH 3/3] added prefix/suffix variable for customizability --- lib/git.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index d6cee37c..a52f82de 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -62,7 +62,8 @@ function git_prompt_ahead() { # Gets the number of commits ahead from remote function git_commits_ahead() { if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')" + COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ') + echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" fi }