Created
July 31, 2012 14:54
-
-
Save pcapriotti/3217608 to your computer and use it in GitHub Desktop.
summary of branches
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 | |
# based on https://gist.github.com/1288596 | |
RED="\033[0;31m" | |
YELLOW="\033[0;33m" | |
GREEN="\033[0;32m" | |
NOCOLOR="\033[00m" | |
BOLD="\033[1;37m" | |
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \ | |
while read local remote | |
do | |
[ -z "$remote" ] && remote="master" | |
git rev-list --left-right ${local}...${remote} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue | |
LEFT_AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta) | |
RIGHT_AHEAD=$(grep -c '^>' /tmp/git_upstream_status_delta) | |
BRANCH_NAME=$(echo -e "$local:" | sed -e :a -e 's/^.\{1,20\}$/& /;ta') | |
echo -ne "${BOLD}${BRANCH_NAME}${NOCOLOR}" | |
if [ "$LEFT_AHEAD" -gt 0 ]; then | |
if [ "$RIGHT_AHEAD" -gt 0 ]; then | |
STATUS="diverged ($LEFT_AHEAD ahead, $RIGHT_AHEAD behind)" | |
COLOR="$RED" | |
else | |
STATUS="ahead ($LEFT_AHEAD commits)" | |
COLOR="$GREEN" | |
fi | |
elif [ "$RIGHT_AHEAD" -gt 0 ]; then | |
COLOR="$YELLOW" | |
STATUS="behind ($RIGHT_AHEAD commits)" | |
else | |
COLOR="" | |
STATUS="clean" | |
fi | |
STATUS=$(echo -e "$STATUS" | sed -e :a -e 's/^.\{1,36\}$/& /;ta') | |
echo -ne "${COLOR}${STATUS}${NOCOLOR}" | |
echo "from $remote" | |
rm -f /tmp/git_upstream_status_delta | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment