Created
January 25, 2018 15:27
-
-
Save hudson155/d88cf3dffe3397627af1a005eb721be1 to your computer and use it in GitHub Desktop.
Check all repos for cleanliness
This file contains 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
#!/usr/bin/env bash | |
set -e | |
# List repositories | |
repos=$(find . -name ".git" | sed 's/^\.\/\(.*\)\/\.git$/\1/') | |
# Find longest repository name | |
longestName=0 | |
while read -r repo; do | |
nameLength=${#repo} | |
if (( nameLength > longestName )); then | |
longestName=$nameLength | |
fi | |
done <<< "$repos" | |
error=0 | |
while read -r repo; do | |
nameLength=${#repo} | |
cd ${repo} | |
echo -n "$repo" | |
printf ' %.0s' $(seq 1 $(( longestName - nameLength + 1 ))) | |
echo -n "| " | |
if [ ! git fetch &> /dev/null ]; then | |
error=1 | |
echo -n "Fetch failed" | |
elif [[ ! $(git branch | grep '* master') ]]; then | |
error=1 | |
echo -n "Not on master branch" | |
elif [[ -n $(git status -s) ]]; then | |
error=1 | |
echo -n "Not clean" | |
elif [ 1 != $(git branch | wc -l) ]; then | |
error=1 | |
echo -n "Stale branches" | |
elif [ 0 != $(git stash list | wc -l) ]; then | |
error=1 | |
echo -n "Stashes exist" | |
else | |
echo -n "OK" | |
fi | |
echo "" | |
cd .. | |
done <<< "$repos" | |
exit $error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment