From ec8c209f07d146a86ca99169801080975711b3a7 Mon Sep 17 00:00:00 2001
From: Itzik Ephraim <oranja@gmail.com>
Date: Sat, 2 Jan 2016 21:20:52 +0200
Subject: [PATCH] A different approach in git_ahead

---
 lib/git/git_ahead.fish | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/lib/git/git_ahead.fish b/lib/git/git_ahead.fish
index af6c21f..16aa924 100644
--- a/lib/git/git_ahead.fish
+++ b/lib/git/git_ahead.fish
@@ -1,15 +1,22 @@
 function git_ahead -a ahead behind diverged none
-  git_is_repo; and begin
-    test -z "$ahead"; and set ahead "+"
-    test -z "$behind"; and set behind "-"
-    test -z "$diverged"; and set diverged "±"
-    test -z "$none"; and set none ""
-    command git rev-list --left-right "@{upstream}...HEAD" ^/dev/null \
-    | awk "/>/ {a += 1} /</ {b += 1} \
-      {if (a > 0) nextfile} END \
-      {if (a > 0 && b > 0) print \"$diverged\"; \
-      else if (a > 0) print \"$ahead\"; \
-      else if (b > 0) print \"$behind\";
-      else printf \"$none\"}"
+  not git_is_repo; and return
+
+  set -l commit_count (command git rev-list --count --left-right "@{upstream}...HEAD" ^/dev/null)
+
+  switch "$commit_count"
+  case ""
+    # no upstream
+  case "0"\t"0"
+    test -z "$ahead"; and echo "$ahead"
+      or echo ""
+  case "*"\t"0"
+    test -z "$behind"; and echo "$behind"
+      or echo "-"
+  case "0"\t"*"
+    test -z "$ahead"; and echo "$ahead"
+      or echo "+"
+  case "*"
+    test -z "$diverged"; and echo "$diverged"
+      or echo "±"
   end
 end
-- 
GitLab