]> git.phdru.name Git - git-scripts.git/commitdiff
Refactor(ls-not-pushed): Show behind/ahead counters
authorOleg Broytman <phd@phdru.name>
Mon, 28 Dec 2020 13:01:37 +0000 (16:01 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 28 Dec 2020 13:01:37 +0000 (16:01 +0300)
ls-not-pushed

index bc950e5c678b24217b34858b1366418a66133d69..8966c5928735b8a69b92ad9d8d866f8031b7ad38 100755 (executable)
@@ -1,2 +1,21 @@
 #! /bin/sh
 #! /bin/sh
-if git branch --verbose | grep -q "ahead\|behind"; then pwd; fi
+if git branch --verbose | grep -q "ahead\|behind"; then
+  up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
+  if [ -n "$up" -a "$up" != "@{u}" ]; then
+      set -- `git rev-list --count --left-right @{u}...HEAD`
+      left=$1
+      right=$2
+      s=''
+      if [ "$left" -gt 0 ]; then
+          s="$s-$left"
+      fi
+      if [ "$right" -gt 0 ]; then
+          s="$s+$right"
+      fi
+  fi
+  if [ -n "$s" ]; then
+     echo `pwd`: $s
+  else
+     pwd
+  fi
+fi