Skip to content

Instantly share code, notes, and snippets.

@hudson155
Created January 25, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hudson155/d88cf3dffe3397627af1a005eb721be1 to your computer and use it in GitHub Desktop.
Save hudson155/d88cf3dffe3397627af1a005eb721be1 to your computer and use it in GitHub Desktop.
Check all repos for cleanliness
#!/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