Has anyone used ktfmt-gradle plugin as a pre-commi...
# ktfmt
l
Has anyone used ktfmt-gradle plugin as a pre-commit hook? https://github.com/cortinico/ktfmt-gradle#using-with-a-pre-commit-hook- I'm a bit unclear on what those docs are recommending. Is the implication that you'd need to figure out using git which files were changed in order to pass to the
--include-only
option?
g
Hey, Yes you can use the
Copy code
--include-only
flag to control which files you want ktfmt-gradle to format. That is particularly useful for pre-commit hooks where you don’t want to touch all the other files.
l
Oh hey, the man himself! Thanks
blob grin 1
I since figured that out
So
git diff --name-only --cached
and pass that to
--include-only
Something like that?
Seems I'll just have to wrap in a small bash script when using
precommit
g
correct
l
Thanks for the reply, Nicola. Really appreciate it
And thanks for the plugin
❤️ 1
In your docs here https://github.com/cortinico/ktfmt-gradle#using-with-a-pre-commit-hook-, you have
You can then invoke the task with --include-only and a comma separated list of relative path of files:
but then the example is with a colon, not a comma:
./gradlew ktfmtPrecommit --include-only=src/main/java/File1.kt:src/main/java/File2.kt
I assume colon is correct and not comma?
g
I need to check the implementation code as I don’t recall exactly