How to setup spotless for a git pre commit hook that only check changed files
See original GitHub issueI’m using spotless with an android kotlin project now. And I have spotless set up like this
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
kotlin {
target "**/*.kt"
ktlint(versions.ktlint)
}
}
What I want to do is set up a git pre commit hook that apply gradlew spotlessCheck
before the commit but only on the commited files. It’s something like this eslint-pre-commit-check
I have search around the repo but can’t figure out how to achieve this. Is there any way to do this? Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:28 (11 by maintainers)
Top Results From Across the Web
Apply Spotless formatting with Git pre-commit hook - Medium
Assign all staged files to a variable: This variable will contain the files, which the developer is about to commit. This is needed...
Read more >Supported hooks - pre-commit
github.com/pre-commit/pre-commit-hooks. check-added-large-files - prevents giant files from being committed. check-ast - simply checks whether the files ...
Read more >Spotless code with a git hook - NotesSensei's Blog - wissel.net
There are 3 steps involved for the Maven setup: Obtaining the formatting files, outlined here. Just make sure you are happy with the...
Read more >Formatting in pre-commit hook - Git - JDriven Blog
This scripts tracks any of the java or kotlin files in the staging area. · Formats the code using spotless if there are...
Read more >Git pre-hook: Setup pre-commit hook for Gradle project example
1. Create a pre-hook script, let's create pre-commit file inside a new scripts directory, and we want to run unit tests before code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Understood. Following is my workaround now. Hope it helps someone else who want to achieve this too.
I created a pre-commit hook that formats the code and adds the formatted files that were initially in the staging area back to the staging area in order to commit the actual formatted code. It leaves the other files as is.
you can install it by running this in your repository root: