has anyone worked on ktlint prepush script? i wan...
# ktlint
k
has anyone worked on ktlint prepush script? i want to check issue before code is pushed
c
something like
Copy code
#!/bin/sh
set -eo pipefail

FILES=$(git diff --cached --name-only | grep -i -E "\.kts?" || true)

if [ -n "$FILES" ]
then
    ktlint $FILES
else
    echo "No file for ktlint"
fi
assuming you have the ktlint cli installed.
k
@Chrimaeon is their a way without cli?
c
maybe 😅 you can use gradle if you use ktlint via a tasks, but thats for you to find out how you would do it. 😉
using the cli though is much faster then invoking gradle. which is a great benefit if you want to have it as a pre-push hook for git.
☝️ 2
j
Agree that ktlint cli is the best way to go when making a git hook. Gradle plugins tend to orient towards the project build cycle (what files need to be rebuilt) rather than git state.