Skip to content

Instantly share code, notes, and snippets.

@mrjabba
Created July 27, 2011 17:43
Show Gist options
  • Save mrjabba/1109954 to your computer and use it in GitHub Desktop.
Save mrjabba/1109954 to your computer and use it in GitHub Desktop.
Find any dirty git projects in the current working directory and recursively beneath this directory
#!/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
# 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