Skip to content

Commit dad2af9

Browse files
author
ilya.aliaksandrovich
committedJan 10, 2024
JLLeitschuh#544 make git filter work with any os
1 parent adbbafc commit dad2af9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
 

‎plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ internal fun BaseKtLintCheckTask.applyGitFilter() {
225225
val projectRelativePath = project.rootDir.toPath()
226226
.relativize(project.projectDir.toPath())
227227
.toString()
228+
.replace("\\", "/")
229+
228230
val filesToInclude = (project.property(FILTER_INCLUDE_PROPERTY_NAME) as String)
229-
.split('\n')
230-
.filter { it.startsWith(projectRelativePath) }
231+
.lines()
231232
.map { it.replace("\\", "/") }
233+
.filter { it.startsWith(projectRelativePath) }
232234

233235
if (filesToInclude.isNotEmpty()) {
234236
include { fileTreeElement ->

‎plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt

+17
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ class KtlintPluginTest : AbstractPluginTest() {
307307
}
308308
}
309309

310+
@DisplayName("Internal Git filter works with Windows on MINGW")
311+
@CommonTest
312+
@EnabledOnOs(OS.WINDOWS)
313+
fun gitFilterOnCheckWindowsMingw(gradleVersion: GradleVersion) {
314+
project(gradleVersion) {
315+
withCleanSources()
316+
withFailingSources()
317+
318+
build(
319+
":$CHECK_PARENT_TASK_NAME",
320+
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/CleanSource.kt"
321+
) {
322+
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
323+
}
324+
}
325+
}
326+
310327
@DisplayName("Git filter should respect already applied filters")
311328
@CommonTest
312329
fun gitFilterAlreadyAppliedFilters(gradleVersion: GradleVersion) {

0 commit comments

Comments
 (0)