Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Duplicates no longer skips the home folder's folders for a dotfiles repository

Țugui Dragoșf4f9e601f30a
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
index 0bdd51b7..85eebff2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
@@ -332,16 +332,18 @@ public struct DuplicateFinder: Sendable {
}
}
- /// Whether `folder` is a repository or sits inside one, checking each folder above it up to the home folder
- /// or the root. The walk checks only the folders it finds, and the enumerator never yields the folder it
- /// starts from, so a chosen folder is checked here.
+ /// Whether `folder` is a repository or sits inside one, checking each folder above it up to the root, or up to
+ /// the home folder, which is never asked: dotfiles kept in a repository there make no folder in it a project.
+ /// The walk checks only the folders it finds, and the enumerator never yields the folder it starts from, so a
+ /// chosen folder is checked here.
static func isInsideARepository(_ folder: URL, home: URL) -> Bool {
var url = folder.resolvingSymlinksInPath()
let stop = Self.path(of: home.resolvingSymlinksInPath())
while true {
- if isRepository(url) { return true }
let path = Self.path(of: url)
- guard path != stop, path != "/", !path.isEmpty else { return false }
+ guard path != stop else { return false }
+ if isRepository(url) { return true }
+ guard path != "/", !path.isEmpty else { return false }
let parent = url.deletingLastPathComponent()
guard Self.path(of: parent) != path else { return false }
url = parent
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
index d0adfdf1..9a11670d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
@@ -142,6 +142,20 @@ struct DuplicateFinderTests {
#expect(names(try await scan(directory)) == [["Documents/a.bin", "Documents/b.bin"]])
}
+ /// Dotfiles kept in a repository at the top of the home folder make no folder inside it a repository's.
+ @Test func aRepositoryOfTheHomeFolderLeavesItsFoldersToScan() async throws {
+ let directory = try TemporaryDirectory()
+ let contents = randomData(count: 3_000)
+ try directory.file("home/.git/HEAD")
+ try directory.file("home/Documents/a.bin", contents: contents)
+ try directory.file("home/Documents/b.bin", contents: contents)
+
+ let found = try await scan(directory, folders: ["home/Documents"])
+
+ #expect(found.skippedLocations.isEmpty)
+ #expect(names(found) == [["Documents/a.bin", "Documents/b.bin"]])
+ }
+
/// A repository is left alone whether it is the chosen folder or holds it. The walk never yields the chosen
/// folder itself, so that case is checked on its own.
@Test func leavesAloneAFolderThatIsOrIsInsideARepository() async throws {