Skip to content

Instantly share code, notes, and snippets.

@mrjabba
Created July 27, 2011 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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