From 209efc85e9f2b8950b2e8fe692051ba7a50c9b76 Mon Sep 17 00:00:00 2001 From: fortmarek Date: Mon, 4 Nov 2024 11:14:22 +0100 Subject: [PATCH] fix: matching files with double globstar --- Package.resolved | 4 +-- Package.swift | 2 +- Sources/FileSystem/FileSystem.swift | 1 - Tests/FileSystemTests/FileSystemTests.swift | 31 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Package.resolved b/Package.resolved index 20c8b26..de88d8a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/swift-glob", "state" : { - "revision" : "106ff5ea97cca6ee504765133af3175ecd5ca257", - "version" : "0.3.7" + "revision" : "4762b314c3ade2f2e3d36ab5cd0817bcd952d653", + "version" : "0.3.8" } }, { diff --git a/Package.swift b/Package.swift index 92a6807..df163fa 100644 --- a/Package.swift +++ b/Package.swift @@ -31,7 +31,7 @@ let package = Package( .package(url: "https://github.com/weichsel/ZIPFoundation", .upToNextMajor(from: "0.9.19")), // We are depending on a fork as swift-glob currently can't handle some scenario that we need in tuist/tuist. // For example, the package currently goes through all directories regradless of whether that's necessary.' - .package(url: "https://github.com/tuist/swift-glob", .upToNextMajor(from: "0.3.7")), + .package(url: "https://github.com/tuist/swift-glob", .upToNextMajor(from: "0.3.8")), ], targets: [ .target( diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index 5d8b80e..75a4e8b 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -607,7 +607,6 @@ public struct FileSystem: FileSysteming, Sendable { return Glob.search( directory: URL(string: directory.pathString)!, include: try include - .flatMap { $0.contains("**/") ? [$0.replacingOccurrences(of: "**/", with: ""), $0] : [$0] } .map { try Pattern($0) }, skipHiddenFiles: false ) diff --git a/Tests/FileSystemTests/FileSystemTests.swift b/Tests/FileSystemTests/FileSystemTests.swift index d04fd2d..b259f1d 100644 --- a/Tests/FileSystemTests/FileSystemTests.swift +++ b/Tests/FileSystemTests/FileSystemTests.swift @@ -786,4 +786,35 @@ final class FileSystemTests: XCTestCase, @unchecked Sendable { XCTAssertEqual(got, [symlinkSourceFilePath]) } } + + func test_glob_with_double_directory_wildcard() async throws { + try await subject.runInTemporaryDirectory(prefix: "FileSystem") { temporaryDirectory in + // Given + let firstDirectory = temporaryDirectory.appending(component: "first") + let firstSourceFile = firstDirectory.appending(component: "first.swift") + let secondDirectory = firstDirectory.appending(component: "second") + let secondSourceFile = secondDirectory.appending(component: "second.swift") + let thirdDirectory = secondDirectory.appending(component: "third") + let thirdSourceFile = thirdDirectory.appending(component: "third.swift") + let fourthDirectory = thirdDirectory.appending(component: "fourth") + let fourthSourceFile = fourthDirectory.appending(component: "fourth.swift") + + try await subject.makeDirectory(at: fourthDirectory) + try await subject.touch(firstSourceFile) + try await subject.touch(secondSourceFile) + try await subject.touch(thirdSourceFile) + try await subject.touch(fourthSourceFile) + + // When + let got = try await subject.glob( + directory: temporaryDirectory, + include: ["first/**/third/**/*.swift"] + ) + .collect() + .sorted() + + // Then + XCTAssertEqual(got, [fourthSourceFile, thirdSourceFile]) + } + } }