From dad2af9a28bd7ebddb59186880f6e08254a0c25b Mon Sep 17 00:00:00 2001 From: "ilya.aliaksandrovich" Date: Thu, 4 Jan 2024 16:28:26 +0100 Subject: [PATCH 1/2] #544 make git filter work with any os --- .../org/jlleitschuh/gradle/ktlint/GitHook.kt | 6 ++++-- .../gradle/ktlint/KtlintPluginTest.kt | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt index d43c825a..2d2ecd9d 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt @@ -225,10 +225,12 @@ internal fun BaseKtLintCheckTask.applyGitFilter() { val projectRelativePath = project.rootDir.toPath() .relativize(project.projectDir.toPath()) .toString() + .replace("\\", "/") + val filesToInclude = (project.property(FILTER_INCLUDE_PROPERTY_NAME) as String) - .split('\n') - .filter { it.startsWith(projectRelativePath) } + .lines() .map { it.replace("\\", "/") } + .filter { it.startsWith(projectRelativePath) } if (filesToInclude.isNotEmpty()) { include { fileTreeElement -> diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt index 4e0c62d8..ddcabd30 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt @@ -307,6 +307,23 @@ class KtlintPluginTest : AbstractPluginTest() { } } + @DisplayName("Internal Git filter works with Windows on MINGW") + @CommonTest + @EnabledOnOs(OS.WINDOWS) + fun gitFilterOnCheckWindowsMingw(gradleVersion: GradleVersion) { + project(gradleVersion) { + withCleanSources() + withFailingSources() + + build( + ":$CHECK_PARENT_TASK_NAME", + "-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/CleanSource.kt" + ) { + assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } + } + } + @DisplayName("Git filter should respect already applied filters") @CommonTest fun gitFilterAlreadyAppliedFilters(gradleVersion: GradleVersion) { From 813cba9034b13071df904097a8d7c9dcffcf8575 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sat, 6 Jan 2024 17:51:53 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f4736be..eaa29192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +- fix [#544](https://github.com/JLLeitschuh/ktlint-gradle/issues/544): make git filter work + with any os [#738](https://github.com/JLLeitschuh/ktlint-gradle/pull/738) + ## [12.1.0] - 2024-01-09 - fix detection of android kotlin source directories in AGP >= 7 [#733](https://github.com/JLLeitschuh/ktlint-gradle/pull/733)