Skip to content

Instantly share code, notes, and snippets.

@dcluna
Created August 10, 2015 19:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dcluna/da9a12e16d53d267c1f6 to your computer and use it in GitHub Desktop.
Checks if staging area for git directories given through stdin is empty
#!/bin/bash
# This script checks if the staging area for git directories in $1 is empty
while read line; do
dir=$line
curdir=$PWD
cd $dir
gitroot=`git rev-parse --show-toplevel`
cd $gitroot
if [[ -z "$gitroot" ]]
then
echo "No git directory @ $dir!"
cd $curdir
exit 1
fi
changed=`git status -s | grep -v "^??"`
if [[ -z "$changed" ]]
then
cd $curdir
else
cd $curdir
printf "There are changed files in $dir:\n$changed"
exit 1
fi
done < "${1:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment