GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Windows Compatibility Fix for Git Pre-push Hook by lazer-dev · Pull Request #2562 · diffplug/spotless

Conversation

@lazer-dev

@lazer-dev lazer-dev commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

This PR fixes execution issues of the generated Git hook on Windows systems.

What's changed

  • Correct platform detection using System.getProperty("os.name").toLowerCase().startsWith("win")
  • Automatically uses mvnw.cmd / gradlew.bat on Windows instead of plain mvnw / gradlew
  • Uses relative paths (./mvnw.cmd, ./gradlew.bat) for better portability and shell compatibility
  • Falls back to using globally installed mvn or gradle if wrapper is not found
  • Avoids absolute paths, which can break on Windows because File.getAbsolutePath() returns backslashes () that are not valid in POSIX-compliant sh scripts used by Git hooks

Why

On Windows, Git hooks are executed via sh (e.g., Git Bash), which does not recognize .cmd without an explicit extension and correct formatting.
Additionally, absolute paths on Windows (e.g., D:\project\mvnw.cmd) use backslashes, which cause D:projectmvnw.cmd command not found errors in shell scripts.
These changes ensure consistent behavior across platforms and make the Git hook portable and reliable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chaidat86 reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@lazer-dev
lazer-dev force-pushed the git-pre-push-windows-fix branch 10 times, most recently from cbe5b74 to 2ed283b Compare July 21, 2025 05:09
lazer-dev
lazer-dev commented Jul 21, 2025
View reviewed changes
Comment thread plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessInstallPrePushHookMojoTest.java
}

@Test
public void should_execute_pre_push_script() throws Exception {

@lazer-dev lazer-dev Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to do the same test for Gradle. To properly validate that the script works, a real Gradle wrapper would need to be present in the temp folder to run the plugin with the new changes — which doesn’t seem easy to set up.

Do you think checking it with Maven is sufficient?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nedtwigg nedtwigg Jul 21, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think just Maven is sufficient.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lazer-dev
lazer-dev force-pushed the git-pre-push-windows-fix branch from 840f2d2 to a4af9c5 Compare July 21, 2025 07:22
lazer-dev and others added 5 commits July 21, 2025 11:35
@lazer-dev ntwigg
git pre push hook windows fix
4cf8137
@lazer-dev ntwigg
spotlessApply
1042742
@lazer-dev ntwigg
tests fix
b8e80bc
@lazer-dev ntwigg
execute pre-push hook
776f7d1
ntwigg
Update changelogs.
222085b
@nedtwigg
nedtwigg force-pushed the git-pre-push-windows-fix branch from a4af9c5 to 222085b Compare July 21, 2025 18:37
@nedtwigg
nedtwigg changed the base branch from main to release July 21, 2025 18:38
ntwigg
We should run CI for PRs against release also.
24ca3bc
@nedtwigg
nedtwigg merged commit 5e9df11 into diffplug:release Jul 21, 2025
@nedtwigg

nedtwigg commented Jul 21, 2025

Copy link
Copy Markdown
Member

Published in plugin-gradle 7.2.1 and plugin-maven 2.46.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lazer-dev
lazer-dev deleted the git-pre-push-windows-fix branch July 24, 2025 02:01
chaidat86
chaidat86 approved these changes Aug 2, 2025
View reviewed changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nedtwigg nedtwigg nedtwigg left review comments
+1 more reviewer
@chaidat86 chaidat86 chaidat86 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@lazer-dev @nedtwigg @chaidat86
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.