Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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