#!/bin/bash -e # See http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git runTest(){ if hasStagedChanges; then echo "There are staged changes" fi if hasWorkingChanges; then echo "There are working changes" fi if hasUntrackedChanges; then echo "There are untracked changes" fi } hasStagedChanges(){ ! git diff-index --quiet --cached HEAD } hasWorkingChanges(){ ! git diff-files --quiet } hasUntrackedChanges(){ local u= ! ( u="$( git ls-files --exclude-standard --others )" && [ -z "${u}" ] ) } runTest