Skip to content

Instantly share code, notes, and snippets.

@hudson155 hudson155/git-check
Created Jan 25, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.