Created
August 10, 2015 19:24
-
-
Save dcluna/47fc5af52315f2f2922c to your computer and use it in GitHub Desktop.
Checks if staging area for git directories given through stdin is empty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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