Last active
May 8, 2021 14:44
-
-
Save k3muri84/4246cd4ec42098fce66c169d28aa2812 to your computer and use it in GitHub Desktop.
ktlintFormat pre-commit hook
This file contains 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
#!/bin/sh | |
# based on https://github.com/shyiko/ktlint pre-commit hook | |
# with further tweaks of @neugartf | |
set -e | |
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.kt/ { print $2}')" | |
if [ -z "$CHANGED_FILES" ]; then | |
exit 0 | |
fi; | |
echo "Running ktlint over these files:" | |
echo "$CHANGED_FILES" | |
# Change depending on the format script | |
ktlint -F $CHANGED_FILES | |
echo "$CHANGED_FILES" | while read -r file; do | |
if [ -f $file ]; then | |
git add $file | |
fi | |
done |
neugartf
commented
May 7, 2021
•
thx @neugartf, tweaked my file
Nice! Good idea btw to run ktlint standalone. Running this with gradle takes too much config time currently.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment