https://kotlinlang.org logo
#ktfmt
Title
# ktfmt
l

Levi

11/20/2023, 8:51 PM
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

gammax

11/23/2023, 5:38 PM
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

Levi

11/23/2023, 5:43 PM
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

gammax

11/23/2023, 5:46 PM
correct
l

Levi

11/23/2023, 5:47 PM
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

gammax

12/02/2023, 12:49 AM
I need to check the implementation code as I don’t recall exactly
2 Views