From de250abab0e0933cf3749de519ccc54d698e7232 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 20 Nov 2016 20:10:37 +0200 Subject: [PATCH] bash-prompt: skip comparing with remote if upstream not defined for branch --- bash-prompt.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bash-prompt.sh b/bash-prompt.sh index 467e4b3..959fd02 100644 --- a/bash-prompt.sh +++ b/bash-prompt.sh @@ -55,18 +55,20 @@ __bash_parse_git_branch() { fi # http://stackoverflow.com/a/3278427 - local=$(git rev-parse @) - remote=$(git rev-parse '@{u}') - base=$(git merge-base @ '@{u}') - - if [ $local = $remote ]; then - remote="" - elif [ $local = $base ]; then - remote="${YELLOW}↓" - elif [ $remote = $base ]; then - remote="${YELLOW}↑" - else - remote="${YELLOW}↕" + remote=$(git rev-parse '@{u}' 2>/dev/null) + if [[ -n "$remote" ]]; then + local=$(git rev-parse @) + base=$(git merge-base @ '@{u}') + + if [[ $local = $remote ]]; then + remote="" + elif [[ $local = $base ]]; then + remote="${YELLOW}↓" + elif [[ $remote = $base ]]; then + remote="${YELLOW}↑" + else + remote="${YELLOW}↕" + fi fi echo " (${branch})${remote}${state}" -- 2.44.0