From ddef73a164a363b37fbc427dd15b81db7b3273f9 Mon Sep 17 00:00:00 2001 From: Arialdo Martini Date: Tue, 12 Nov 2013 06:15:22 +0100 Subject: [PATCH] fix #13 The number of commits ahed and behind are correctly calculated --- prompt.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/prompt.sh b/prompt.sh index 46e2965..23740b6 100644 --- a/prompt.sh +++ b/prompt.sh @@ -92,15 +92,9 @@ function build_prompt { can_fast_forward=false commits_diff=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null) - commits_ahead=0 - commits_behind=0 - if [[ $commits_diff =~ .*^\<(..) ]]; then - commits_ahead=${#BASH_REMATCH[@]} - fi - if [[ $commits_diff =~ .*^\>(..) ]]; then - commits_behind=${#BASH_REMATCH[@]} - fi + commits_ahead=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^<" ) + commits_behind=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^>" ) if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then has_diverged=true