-
-
Save vbjay/5701299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# hosted at https://gist.github.com/Mark-Booth/5058384 | |
# forked from https://gist.github.com/lth2h/4177524 @ ae184f1 by mark.booth | |
# forked from https://gist.github.com/jehiah/1288596 @ e357c1e by lth2h | |
# ideas from https://github.com/kortina/bakpak/blob/master/bin/git-branches-vs-origin-master | |
# this prints out some branch status | |
# (similar to the '... ahead' info you get from git status) | |
# example: | |
# $ git branch-status -a | |
# dns_check (ahead 1) | (behind 112) origin/master | |
# master (ahead 2) | (behind 0) origin/master | |
# $ git branch-status | |
# master (ahead 2) | (behind 0) origin/master | |
usage="$(basename "$0") [-hav] -- summarise status of branch(es) | |
where: | |
-h show this help text | |
-a show all branches, not just the current one | |
-m shows branch(es) with respect to origin/master | |
-v verbose, show output even if counts are zero" | |
while getopts 'hamv' option; do | |
case "$option" in | |
h) echo "$usage" | |
exit | |
;; | |
a) filter=refs/heads | |
;; | |
m) originmaster=true | |
;; | |
v) verbose=true | |
;; | |
?) printf "illegal option: '%s'\n" "$OPTARG" >&2 | |
echo "$usage" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
if [ -z $filter ] ; then | |
filter=$(git symbolic-ref -q HEAD) | |
fi | |
git for-each-ref --format="%(refname:short) %(upstream:short)" $filter | \ | |
while read local remote | |
do | |
if [ $originmaster ] ; then | |
remote=origin/master | |
fi | |
[ -z "$remote" ] && continue | |
DELTAS=$(git rev-list --left-right ${local}...${remote}) | |
LEFT_AHEAD=$(echo "$DELTAS" | grep -c '^<') | |
RIGHT_AHEAD=$(echo "$DELTAS" | grep -c '^>') | |
if [ $verbose ] || [ $LEFT_AHEAD -gt 0 ] || [ $RIGHT_AHEAD -gt 0 ] ; then | |
echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment