fix #13 The number of commits ahed and behind are correctly calculated

This commit is contained in:
Arialdo Martini 2013-11-12 06:15:22 +01:00
parent bcee0df296
commit ddef73a164

View File

@ -92,15 +92,9 @@ function build_prompt {
can_fast_forward=false can_fast_forward=false
commits_diff=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null) 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=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^<" )
commits_ahead=${#BASH_REMATCH[@]} commits_behind=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^>" )
fi
if [[ $commits_diff =~ .*^\>(..) ]]; then
commits_behind=${#BASH_REMATCH[@]}
fi
if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then
has_diverged=true has_diverged=true