You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -142,9 +142,34 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer.
142
142
- If you're stuck on JRE 8, use [`id 'com.diffplug.spotless' version '6.13.0'` or older](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#6130---2023-01-14).
143
143
- If you're stuck on an older version of Gradle, [`id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#451---2020-07-04).
144
144
145
-
### Git hook
145
+
### Git pre-push hook
146
146
147
-
TODO
147
+
You can install a Git pre-push hook that ensures code is properly formatted before being pushed to a remote repository.
148
+
This helps catch formatting issues early — before CI fails — and is especially useful for teams not using IDE integrations or pre-commit tools.
149
+
150
+
#### What the hook does
151
+
152
+
When installed, the Git `pre-push` hook will:
153
+
154
+
1. Run `spotlessCheck`
155
+
2. If formatting issues are found:
156
+
- It automatically runs `spotlessApply` to fix them
157
+
- Aborts the push with a message
158
+
- You can then commit the changes and push again
159
+
160
+
This ensures your code is always clean before it leaves your machine.
161
+
162
+
#### Installation
163
+
164
+
Run the following task once in your project:
165
+
```console
166
+
gradle spotlessInstallGitPrePushHook
167
+
```
168
+
169
+
This installs a `.git/hooks/pre-push` script that runs `spotlessCheck`, and runs `spotlessApply` if needed.
170
+
171
+
> [!WARNING]
172
+
> The hook will not install automatically — you must run the install command manually.
@@ -147,9 +147,34 @@ Spotless consists of a list of formats (in the example above, `misc` and `java`)
147
147
Spotless requires Maven to be running on JRE 11+. To use JRE 8, go back to [`2.30.0` or older](https://github.com/diffplug/spotless/blob/main/plugin-maven/CHANGES.md#2300---2023-01-13).
148
148
149
149
150
-
### Git hook
150
+
### Git pre-push hook
151
151
152
-
TODO
152
+
You can install a Git pre-push hook that ensures code is properly formatted before being pushed to a remote repository.
153
+
This helps catch formatting issues early — before CI fails — and is especially useful for teams not using IDE integrations or pre-commit tools.
154
+
155
+
#### What the hook does
156
+
157
+
When installed, the Git `pre-push` hook will:
158
+
159
+
1. Run `spotless:check`
160
+
2. If formatting issues are found:
161
+
- It automatically runs `spotless:apply` to fix them
162
+
- Aborts the push with a message
163
+
- You can then commit the changes and push again
164
+
165
+
This ensures your code is always clean before it leaves your machine.
166
+
167
+
#### Installation
168
+
169
+
Run the following task once in your project:
170
+
```console
171
+
mvn spotless:install-git-pre-push-hook
172
+
```
173
+
174
+
This installs a `.git/hooks/pre-push` script that runs `spotless:check`, and runs `spotless:apply` if needed.
175
+
176
+
> [!WARNING]
177
+
> The hook will not install automatically — you must run the install command manually.
0 commit comments