Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 33b29dd

Browse files
committed
Do not compare string paths, use File instead (Windows/Unix path separators)
1 parent 011ac1e commit 33b29dd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/kotlin/com/cherryperry/gfe/CheckGitIgnoreTask.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.gradle.api.file.FileCollection
1313
import org.gradle.api.tasks.InputFiles
1414
import org.gradle.api.tasks.SkipWhenEmpty
1515
import org.gradle.api.tasks.TaskAction
16+
import java.io.File
1617
import java.io.IOException
1718

1819
/**
@@ -40,32 +41,33 @@ open class CheckGitIgnoreTask : BaseTask(), PlainFilesAware {
4041
} catch (exception: IOException) {
4142
throw GradleException("Git repository was not found at path $projectDir", exception)
4243
}
43-
val plainFiles = plainFiles.mapNotNull { it.toRelativeString(projectDir.asFile) }.toHashSet()
44+
val plainFiles = plainFiles.toHashSet()
4445
TreeWalk(git.repository).use { treeWalk -> walkThrough(git, treeWalk, plainFiles) }
4546
failTaskIfAnyFilesLeft(plainFiles)
4647
}
4748

48-
private fun walkThrough(git: Git, treeWalk: TreeWalk, plainFiles: MutableCollection<String>) {
49+
private fun walkThrough(git: Git, treeWalk: TreeWalk, plainFiles: MutableCollection<File>) {
4950
val fileTreeIterator = FileTreeIterator(git.repository)
5051
fileTreeIterator.setWalkIgnoredDirectories(true)
5152
treeWalk.addTree(fileTreeIterator)
5253
treeWalk.isRecursive = true
5354
while (treeWalk.next() && plainFiles.isNotEmpty()) {
5455
if (treeWalk.getTree(WorkingTreeIterator::class.java).isEntryIgnored) {
55-
val path = treeWalk.pathString
56-
val removed = plainFiles.remove(path)
56+
val file = projectDir.file(treeWalk.pathString).asFile
57+
val removed = plainFiles.remove(file)
5758
if (removed) {
58-
logger.info("$path is ignored")
59+
logger.info("$file is ignored")
5960
}
6061
}
6162
}
6263
}
6364

64-
private fun failTaskIfAnyFilesLeft(relativePlainFiles: Collection<String>) {
65+
private fun failTaskIfAnyFilesLeft(relativePlainFiles: Collection<File>) {
6566
if (relativePlainFiles.isNotEmpty()) {
6667
relativePlainFiles.forEach { plainFile ->
68+
val fileForLog = plainFile.relativeToOrNull(projectDir.asFile) ?: plainFile
6769
logger.error(
68-
"${projectDir.file(plainFile)} is not ignored by any ${Constants.DOT_GIT_IGNORE} files of project"
70+
"$fileForLog is not ignored by any ${Constants.DOT_GIT_IGNORE} files of project"
6971
)
7072
}
7173
throw GradleException("Some plain files are not ignored by git, see log above")

0 commit comments

Comments
 (0)