Skip to content

Instantly share code, notes, and snippets.

@ninjazoete
Created March 13, 2019 07:05
Show Gist options
  • Save ninjazoete/e297fe532307d7b85f55763b32abadd8 to your computer and use it in GitHub Desktop.
Save ninjazoete/e297fe532307d7b85f55763b32abadd8 to your computer and use it in GitHub Desktop.
#!/bin/sh
# [SwiftFormat Pass]
isCleanDiff() {
if git diff-index --quiet HEAD; then
return 0
else
return 1
fi
}
# Make sure that no other changes were made before, if they were
# stash them and proceed.
if ! isCleanDiff; then
echo "[SwiftFormat Pass] You had changes that were not really meant to be added by pre-push "
git stash
echo "[SwiftFormat Pass] Stashed changes"
fi
# One pass with swiftformat before pushing
swiftformat .
# and a generic commit if any changes were made using swiftformat
if ! isCleanDiff; then
# swift did correct files, commit changes
echo "[SwiftFormat Pass] Generated changes"
echo "[SwiftFormat Pass] Staging all files to commit"
git add .
echo "[SwiftFormat Pass] Commiting"
git commit -m "[Swiftformat-automated] swiftformat corrections pass"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment