set -eo pipefail
function revert_git_stash {
>&2 echo "Unstashing uncommited changes..."
git stash pop -q
}
set +e
git diff-files --quiet
is_unclean=$?
set -e
if [ $is_unclean -ne 0 ]; then
>&2 echo "Stashing uncommited changes..."
git stash -q --keep-index
trap revert_git_stash EXIT
fi