Last active
December 21, 2015 05:28
-
-
Save mattes/6256810 to your computer and use it in GitHub Desktop.
Git pre-commit hook. Verify this repository has a clean work tree.
This file contains 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/sh | |
# see also ... | |
# https://github.com/git/git/blob/master/git-sh-setup.sh#L168 | |
# Verify this repository has a clean work tree. | |
# Return false (= 0), if there are any unstaged/ uncommitted changes. | |
# Return true (= 1), if there are no changes in the repository. | |
has_clean_work_tree () { | |
git rev-parse --quiet --verify HEAD &> /dev/null || return 0 # false | |
git update-index --quiet --ignore-submodules --refresh | |
if ! git diff-files --quiet --ignore-submodules | |
then | |
return 0 # false | |
fi | |
if ! git diff-index --cached --quiet --ignore-submodules HEAD -- | |
then | |
return 0 # false | |
fi | |
return 1 # true | |
} | |
has_clean_work_tree | |
if [ "$?" == 0 ]; then | |
# no clean work tree ... | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment