Skip to content

Commit 259ec38

Browse files
author
ntwigg
committed
Modify git-hook docs, with an eye towards a future where there is both a pre-push hook or a pre-commit hook, depending on what the user prefers.
1 parent 525e70e commit 259ec38

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

plugin-gradle/README.md

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
5353

5454
- [**Quickstart**](#quickstart)
5555
- [Requirements](#requirements)
56-
- [Git pre-push hook](#git-pre-push-hook)
56+
- [Git hook (optional)](#git-hook)
5757
- [Linting](#linting)
5858
- **Languages**
5959
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat), [IntelliJ IDEA](#intellij-idea))
@@ -142,34 +142,19 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer.
142142
- 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).
143143
- 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).
144144

145-
### Git pre-push hook
145+
### Git hook
146146

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.
147+
If you want, you can run `./gradlew spotlessInstallGitPrePushHook` and it will install a hook such that
149148

150-
#### What the hook does
151-
152-
When installed, the Git `pre-push` hook will:
153-
154-
1. Run `spotlessCheck`
149+
1. When you push, it runs `spotlessCheck`
155150
2. If formatting issues are found:
156151
- It automatically runs `spotlessApply` to fix them
157152
- Aborts the push with a message
158153
- You can then commit the changes and push again
159154

160155
This ensures your code is always clean before it leaves your machine.
161156

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.
157+
If you prefer instead to have a "pre-commit" hook so that every single commit is clean, see [#623](https://github.com/diffplug/spotless/issues/623) for a workaround or to contribute a permanent fix.
173158

174159
### Linting
175160

plugin-maven/README.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ user@machine repo % mvn spotless:check
3737

3838
- [**Quickstart**](#quickstart)
3939
- [Requirements](#requirements)
40-
- [Git pre-push hook](#git-pre-push-hook)
40+
- [Git hook (optional)](#git-hook)
4141
- [Binding to maven phase](#binding-to-maven-phase)
4242
- **Languages**
4343
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat), [IntelliJ IDEA](#intellij-idea))
@@ -147,34 +147,19 @@ Spotless consists of a list of formats (in the example above, `misc` and `java`)
147147
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).
148148

149149

150-
### Git pre-push hook
150+
### Git hook
151151

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.
152+
If you want, you can run `mvn spotless:install-git-pre-push-hook` and it will install a hook such that
154153

155-
#### What the hook does
156-
157-
When installed, the Git `pre-push` hook will:
158-
159-
1. Run `spotless:check`
154+
1. When you push, it runs `spotless:check`
160155
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
156+
- It automatically runs `spotless:apply` to fix them
157+
- Aborts the push with a message
158+
- You can then commit the changes and push again
164159

165160
This ensures your code is always clean before it leaves your machine.
166161

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.
162+
If you prefer instead to have a "pre-commit" hook so that every single commit is clean, see [#623](https://github.com/diffplug/spotless/issues/623) for a workaround or to contribute a permanent fix.
178163

179164
### Binding to maven phase
180165

0 commit comments

Comments
 (0)