Created
September 16, 2016 19:54
-
-
Save kentquirk/bbe9ed2290f2390af13222e69c4db25e to your computer and use it in GitHub Desktop.
gitstat bash script
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 | |
# checks status in all the git repositories below this one | |
# only prints status for those that aren't on master with no changes since the last tag | |
alltags() { | |
git tag | egrep "v[0-9]+\.[0-9]+\.[0-9]+(-.+)?" |tr '.-' ' *' |sort --numeric-sort --key 1.1 --key 2 --key 3 |tr ' *' '.-' | |
} | |
lasttag() { | |
alltags |tail -1 | |
} | |
gitlog1() { | |
git log --max-count 1 --pretty=oneline --abbrev-commit --no-merges $1 | |
} | |
# if we're in a folder with .git or one of its children, we should go up to its parent. | |
if [ -d ../../.git ]; then | |
cd ../../.. | |
elif [ -d ../.git ]; then | |
cd ../.. | |
elif [ -d .git ]; then | |
cd .. | |
fi | |
BAD='\x1b[22;31m' # red | |
GOOD='\x1b[22;32m' # green | |
NOCOL='\x1b[0m' | |
PRINTALL="false" | |
REPOLIST=$(find . -name ".git" -depth 2 |sed s/\.git// |sed s@\./@@ |sed s@/@@) | |
while [ -n "$1" ]; do | |
if [ /$1/ == /--nocolor/ ]; then | |
BAD='' | |
GOOD='' | |
NOCOL='' | |
fi | |
if [ "$1" == "--all" ]; then | |
PRINTALL="true" | |
fi | |
if [ "$1" == "--required" ]; then | |
REPOLIST=$(cat "gotools/scripts/required_repos.txt") | |
fi | |
if [ "$1" == "-h" ]; then | |
echo "status [args]" | |
echo "-h prints this help" | |
echo "--nocolor suppresses colorizing of results" | |
echo "--required examines only the repositories in required_repos.txt" | |
echo "--all prints all items -- otherwise, only exceptions are printed" | |
echo " exceptions are repos not on master, not clean, or last tag not at head" | |
exit | |
fi | |
shift | |
done | |
# colorize(text, good) | |
colorize() { | |
if [ "$1" == "$2" ]; then | |
echo $GOOD$1$NOCOL | |
else | |
echo $BAD$1$NOCOL | |
fi | |
} | |
doall() { | |
for i in $REPOLIST; do | |
cd $i | |
BRANCH=$(git branch |grep '*' |cut -c 3-99) | |
STATUS=$(git status --porcelain |cut -c 1-2 |sort |uniq |tr '\n' ' '|sed -e "s/M/modified /" -e "s/??/untracked /" -e "s/UU/--uncompleted-merge-- /" -e "s/A/added /" -e "s/D/deleted /" -e "s/R/renamed /" -e "s/C/copied /" -e "s/U/updated /"|tr -d '\n' | sed -e "s/^ //" -e "s/ */ /g") | |
LASTTAG=$(lasttag) | |
TAGLOG=$(gitlog1 $LASTTAG) | |
CURLOG=$(gitlog1) | |
UPTODATE="" | |
if [ "$TAGLOG" != "$CURLOG" ]; then | |
UPTODATE=$(colorize "(tag is not HEAD)" "") | |
fi | |
if [ -z "$LASTTAG" ]; then | |
LASTTAG="--" | |
fi | |
if [ -z "$STATUS" ]; then | |
STATUS="--" | |
fi | |
if [ "$STATUS" != "--" -o "$BRANCH" != "master" -o $PRINTALL == "true" -o "$UPTODATE" != "" ]; then | |
echo -e "$i:@[ $(colorize $BRANCH "master") ]@$STATUS@$LASTTAG@$UPTODATE" | |
fi | |
cd .. | |
done | |
} | |
doall |column -s @ -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment