From 7bf90d46de8be4d84cd98808d051afc0125ba88e Mon Sep 17 00:00:00 2001 From: Arialdo Martini Date: Thu, 14 Nov 2013 12:55:00 +0100 Subject: [PATCH] Fix, upstream should be correctly calculated with git < v1.8, fix by @celeron55 --- base.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/base.sh b/base.sh index 14d6930..d5afa8f 100644 --- a/base.sh +++ b/base.sh @@ -26,7 +26,7 @@ function build_prompt { just_init=true else upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null) - if [ -n $upstream -a "$upstream" != "@upstream}" ]; then has_upstream=true; else has_upstream=false; fi + if [ -n $upstream -a "$upstream" != "@{upstream}" ]; then has_upstream=true; else has_upstream=false; fi git_status=$(git status --porcelain 2> /dev/null) @@ -53,9 +53,10 @@ function build_prompt { commits_diff=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null) - 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 [[ $has_upstream == true ]]; then + 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 "^>" ) + fi if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then has_diverged=true fi