| CHIP_ROOT=$(cd "$here/.." && pwd) |
| SAVED_UNSTAGED_FILE=$(git rev-parse --short HEAD)-unstaged.diff |
| if [[ $SAVED_UNSTAGED -ne 0 ]]; then |
| git diff --output="$SAVED_UNSTAGED_FILE" |
| git apply -R "$SAVED_UNSTAGED_FILE" |
| if [[ $SAVED_UNSTAGED -ne 0 ]]; then |
| git apply "$SAVED_UNSTAGED_FILE" |
| rm "$SAVED_UNSTAGED_FILE" |
| if [[ $RESTYLED -ne 0 ]]; then |
| # Reset the changes introduced by restyle |
| git stash push -q --keep-index |
| trap "revert_if_needed; exit 1" SIGINT SIGTERM SIGKILL |
| # If there are unstaged files, save them for now |
| "$CHIP_ROOT"/scripts/helpers/restyle-diff.sh |
| FAILED_COMMIT="$RESTYLED" |
| if [[ $FAILED_COMMIT -ne 0 ]]; then |
| echo "Commit Failed: Code needs restyling before committing." |
| echo "Restyling can be done by running $CHIP_ROOT/scripts/helpers/restyle-diff.sh" |
| echo "Code doesn't need restyling. Committing." |