Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#544 make git filter work with any os #738

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading