Created
February 16, 2013 21:22
-
-
Save IQAndreas/4968787 to your computer and use it in GitHub Desktop.
Shell function that requires that a GIT index is clean before running a command. The script allows modified or untracked files to exist in the repository, so long as the index 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
function require_clean_index() | |
{ | |
# TODO: Allow to manually set which git directory | |
git diff-index --quiet --cached HEAD | |
if [ $? -ne 0 ]; then | |
echo "This command requires a clean index. Please reset or commit changes and try again."; | |
exit 2; | |
fi | |
} | |
# ----- Example use ----- | |
require_clean_index && | |
git add src/modified-file && | |
git commit -m "Modified the file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment