spotify / fmt-maven-plugin

Opinionated Maven Plugin that formats your Java code.
MIT License
326 stars 62 forks source link

Staged files only #168

Open alexmiranda opened 1 year ago

alexmiranda commented 1 year ago

Is there any way to apply formatting to git staged files only? e.g. invoked with a pre-commit hook

klaraward commented 1 year ago

I think you should be able to do something with the fileNamesPattern config option, which is used like this - https://github.com/spotify/fmt-maven-plugin/blob/main/src/main/java/com/spotify/fmt/Formatter.java#L104.

fileNamesPattern is a regex, so something like (path-to-first-file|path-to-second-file....) should do, if you can build up that regex in your pre-commit hook.