From e5f3c25f6d15f45549d8aabeff13c1f7435cb636 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Thu, 13 Feb 2025 13:21:34 +0000 Subject: [PATCH] [JEWEL] Fix the git hook on non-Windows OSes It also includes a tentative Windows fix, but deactivated as I can't test it. --- platform/jewel/settings.gradle.kts | 80 ++++++++++++++++-------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/platform/jewel/settings.gradle.kts b/platform/jewel/settings.gradle.kts index 9efc55f9f99da..f4a4b0430baaf 100644 --- a/platform/jewel/settings.gradle.kts +++ b/platform/jewel/settings.gradle.kts @@ -12,9 +12,7 @@ pluginManagement { gradlePluginPortal() mavenCentral() } - plugins { - kotlin("jvm") version "2.1.0" - } + plugins { kotlin("jvm") version "2.1.0" } } dependencyResolutionManagement { @@ -52,7 +50,7 @@ include( ":samples:showcase", ":samples:standalone", ":ui", - ":ui-test", + ":ui-tests", ) gradleEnterprise { @@ -66,45 +64,51 @@ gradleEnterprise { val isWindows get() = System.getProperty("os.name").contains("win", true) -val gradleCommand: String by -lazy(LazyThreadSafetyMode.NONE) { - val gradlewFilename = - if (isWindows) { - "gradlew.bat" - } else { - "gradlew" - } - - val gradlew = File(rootProject.projectDir, gradlewFilename) - if (gradlew.exists() && gradlew.isFile && gradlew.canExecute()) { - logger.info("Using gradlew wrapper at ${gradlew.invariantSeparatorsPath}") - gradlew.invariantSeparatorsPath - } else { - "gradle" - } -} - val shebang = if (isWindows) "" else "#!/bin/sh" -/* -// This is broken on Windows, please do not enable it again until it is fixed. gitHooks { hook("pre-push") { - from(shebang) { - // language=Shell Script - """ - |#### Note: this hook was autogenerated. You can edit it in settings.gradle.kts - |GRADLEW=$gradleCommand - |if ! ${'$'}GRADLEW ktfmtCheck ; then - | ${'$'}GRADLEW ktfmtFormat - | echo 1>&2 "\nktfmt found problems; commit the result and re-push" - | exit 1 - |fi - | - """ - .trimMargin() + if (!isWindows) { + from(shebang) { + """ + |set -x + |#### Note: this hook was autogenerated. You can edit it in Jewel's settings.gradle.kts + |GRADLEW="./gradlew" + |OLD_DIR=$(pwd) + |cd "${rootDir.absolutePath}" + |if ! ${'$'}GRADLEW ktfmtCheck ; then + | ${'$'}GRADLEW ktfmtFormat + | echo 1>&2 "\nktfmt found problems; commit the result and re-push" + | cd ${'$'}OLD_DIR + | exit 1 + |fi + |cd ${'$'}OLD_DIR + | + """ + .trimMargin() + } + } else { + // TODO @jakub fix this for Windows — the following _should_ work but I can't test it +// from(shebang) { +// """ +// |:: Note: this hook was autogenerated. You can edit it in Jewel's settings.gradle.kts +// |SET GRADLEW=gradlew.bat +// | +// |SET OLD_DIR=%CD% +// |CD /D ${rootDir.absolutePath} +// |%GRADLEW% ktfmtCheck || ( +// | %GRADLEW% ktfmtFormat +// | echo "ktfmt found problems; commit the result and re-push" +// | CD /D %OLD_DIR% +// | EXIT 1 +// |) +// | +// |CD /D %OLD_DIR% +// """ +// .trimMargin() +// } } } createHooks(overwriteExisting = true) -}*/ +}