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

Fix searching from inside a hidden directory #2377

Merged
merged 2 commits into from
Nov 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ internal fun FileSystem.fileSequence(
dirAttr: BasicFileAttributes,
): FileVisitResult =
if (Files.isHidden(dirPath)) {
LOGGER.trace { "- Dir: $dirPath: Ignore" }
FileVisitResult.SKIP_SUBTREE
if (dirPath == commonRootDir) {
LOGGER.trace { "- Dir: $dirPath: Traverse started from hidden directory" }
FileVisitResult.CONTINUE
} else {
LOGGER.trace { "- Dir: $dirPath: Ignore traversal of hidden directory" }
FileVisitResult.SKIP_SUBTREE
}
} else {
LOGGER.trace { "- Dir: $dirPath: Traverse" }
FileVisitResult.CONTINUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ internal class FileUtilsTest {
private val javaFileRootDirectory = "Root.java"
private val ktFileRootDirectory = "Root.kt"
private val ktsFileRootDirectory = "Root.kts"
private val javaFileInHiddenDirectory = "project1/.git/Ignored.java"
private val ktFileInHiddenDirectory = "project1/.git/Ignored.kt"
private val ktsFileInHiddenDirectory = "project1/.git/Ignored.kts"
private val javaFileInHiddenDirectory = "project1/.hidden/Ignored.java"
private val ktFileInHiddenDirectory = "project1/.hidden/Ignored.kt"
private val ktsFileInHiddenDirectory = "project1/.hidden/Ignored.kts"
private val javaFileInProjectRootDirectory = "project1/ProjectRoot.java"
private val ktFileInProjectRootDirectory = "project1/ProjectRoot.kt"
private val ktsFileInProjectRootDirectory = "project1/ProjectRoot.kts"
Expand Down Expand Up @@ -106,6 +106,17 @@ internal class FileUtilsTest {
)
}

@Test
fun `Given the root directory where scanning starts is hidden, then the patterns should work`() {
val foundFiles =
getFiles(
patterns = listOf("*.kt"),
rootDir = ktlintTestFileSystem.resolve("project1/.hidden"),
)

assertThat(foundFiles).containsExactlyInAnyOrder(ktFileInHiddenDirectory)
}

@Test
fun `Given some patterns including a negate pattern and no workdir then select all files except files in the negate pattern`() {
val foundFiles =
Expand Down