Skip to content

Conversation

lazer-dev
Copy link
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.

@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
}

@Test
public void should_execute_pre_push_script() throws Exception {
Copy link
Contributor Author

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?

Copy link
Member

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.

@lazer-dev lazer-dev force-pushed the git-pre-push-windows-fix branch from 840f2d2 to a4af9c5 Compare July 21, 2025 07:22
@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
@nedtwigg nedtwigg merged commit 5e9df11 into diffplug:release Jul 21, 2025
14 checks passed
@nedtwigg
Copy link
Member

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

@lazer-dev lazer-dev deleted the git-pre-push-windows-fix branch July 24, 2025 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants