Skip to content

Instantly share code, notes, and snippets.

@dcluna
Created August 10, 2015 19:24
Show Gist options
  • Select an option

  • Save dcluna/47fc5af52315f2f2922c to your computer and use it in GitHub Desktop.

Select an option

Save dcluna/47fc5af52315f2f2922c 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
# echo "Currently in git root $PWD"
if [[ -z "$gitroot" ]]
then
echo "No git directory @ $dir!"
cd $curdir
exit 1
fi
# check if gitroot is empty here...
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