Created
January 3, 2015 02:45
-
-
Save gsingh93/20d4cbbe1547c85f25ae to your computer and use it in GitHub Desktop.
Finds git repos in a folder with a dirty index, uncommitted changes, or unpushed commits.
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
#!/bin/bash | |
# This script finds three types of Git repos | |
# 1. Repos that have a dirty index or uncommitted changes | |
# 2. Repos that have committed changes that aren't pushed to the remote branch | |
# 3. Repos that have no remote branch | |
# | |
# Type 2 only works with the master branch, and the others only work with the branch the repo is currently on | |
depth=3 | |
repos=$(find ./ -maxdepth $depth -name .git -type d | xargs -n 1 dirname) | |
echo "Dirty repos:" | |
for file in $repos; do | |
(cd $file && (git diff-files --quiet && git diff-index --quiet --cached HEAD)) | |
if [[ $? -eq 1 ]]; then | |
echo $file | |
fi | |
done | |
echo "Unpushed repos:" | |
for file in $repos; do | |
cd $file | |
git ls-remote &> /dev/null | |
if [[ $? -ne 0 ]]; then | |
cd - > /dev/null; | |
continue | |
fi | |
output=$(git rev-list origin/master..master) | |
if [[ "x$output" != "x" ]]; then | |
echo $file | |
fi | |
cd - > /dev/null | |
done | |
echo "Repos with no remote:" | |
for file in $repos; do | |
(cd $file && git ls-remote &> /dev/null) | |
if [[ $? -ne 0 ]]; then | |
echo $file | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment