-
-
Save breml/111dceb0ebdb6f38b0506c0c898d1ca4 to your computer and use it in GitHub Desktop.
Find any dirty git projects as well as local only branches in the current working directory and recursively beneath this directory
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 | |
############################################################################## | |
# Find any dirty git projects in the current working directory | |
# and recursively beneath this directory | |
# copied with thanks to Matthew from | |
# https://github.com/matthewmccullough/scripts/blob/master/finddirtygit | |
# | |
# USAGE: | |
# finddirtygit | |
# Quiet mode that outputs only the project that is dirty | |
# finddirtygit -v | |
# Verbose mode that outputs what files are dirty | |
############################################################################## | |
# Find all directories that have a .git directory in them | |
for gitprojpath in `find . -type d -name .git | sed "s/\/\.git//"`; do | |
# Save the current working directory before CDing for git's purpose | |
pushd . >/dev/null | |
# Switch to the git-enabled project directory | |
cd $gitprojpath | |
# Are there any changed files in the status output? | |
isdirty=$(git status -s | grep "^.*") | |
if [ -n "$isdirty" ]; then | |
# Should output be verbose? | |
if [ "$1" = "-v" ]; then | |
echo | |
echo "DIRTY:" $gitprojpath | |
git status -s | |
# Or should output be quiet? | |
else | |
echo "DIRTY:" $gitprojpath | |
fi | |
fi | |
haslocalbranches=$(git branch -vv | cut -c 3- | awk '$3 !~/\[/ { print $1 }') | |
if [ -n "$haslocalbranches" ]; then | |
# Should output be verbose? | |
if [ "$1" = "-v" ]; then | |
echo | |
echo "LOCALBRANCHES:" $gitprojpath | |
echo $haslocalbranches | |
# Or should output be quiet? | |
else | |
echo "LOCAL BRANCHES:" $gitprojpath | |
fi | |
fi | |
# Return to the starting directory, suppressing the output | |
popd >/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment