Last active
July 20, 2021 06:36
-
-
Save muthuraj57/d0de2f52bfcfeb7750bcca046753359e to your computer and use it in GitHub Desktop.
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/bash | |
set -e | |
# Ref: https://blog.jdriven.com/2020/11/formatting-in-pre-commit-hook/ | |
# command taken from https://github.com/JLLeitschuh/ktlint-gradle task addKtlintFormatGitPreCommitHook | |
filesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.java|\.kt/ { print $2}')" | |
echo "files to format $filesToFormat" | |
for sourceFilePath in $filesToFormat; do | |
if [ -f "$sourceFilePath" ]; then | |
./gradlew spotlessApply -PspotlessIdeHook="$(pwd)/$sourceFilePath" | |
git add $sourceFilePath | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment