Skip to content

Instantly share code, notes, and snippets.

@jpardogo
Created October 3, 2019 15:59
Show Gist options
  • Save jpardogo/d18629e0f472f11317d105d2aa2c2b06 to your computer and use it in GitHub Desktop.
Save jpardogo/d18629e0f472f11317d105d2aa2c2b06 to your computer and use it in GitHub Desktop.
Pre-Push Git Hook for ktlint formatting
#!/bin/sh
# Place this hook in the repo .git/hooks folder.
# make sure you chmod a+x this hook in terminal.
# Otherwise, you'll tear your hair out when you think it should run but it doesn't.
# Video Pre-Push Git Hook for ktlint Formatting With Plugin: https://www.youtube.com/watch?v=eysVDO2_X0s
# Ktlint Plugin: org.jlleitschuh.gradle:ktlint-gradle
echo "Checking code formatting"
./gradlew ktlintCheck --daemon
status=$?
if [ "$status" == 0 ] ; then
echo "No formatting issues were found"
exit 0
else
echo>&2 "* There are code formatting issues that must be addressed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment