Fix Git Sync wiping the entire repo when a fresh clone's DB is empty

exportAllConversations()'s orphan-cleanup treated "zero local
conversations" as "every synced conversation was deleted," so a
just-cloned repo on a new machine could get emptied and pushed before
the post-clone import ever ran. orphanedExportFilenames() now returns
no orphans when the local ID set is empty, and cloneRepository()
imports immediately after cloning to close the window entirely.
This commit is contained in:
2026-08-01 10:50:46 +02:00
parent 77223536e9
commit ae3de3d927
2 changed files with 28 additions and 1 deletions
+14
View File
@@ -151,4 +151,18 @@ struct GitSyncServiceTests {
func emptyFileListProducesNoOrphans() {
#expect(GitSyncService.orphanedExportFilenames(currentIds: [UUID().uuidString], files: []).isEmpty)
}
@Test("Empty local conversation list never flags files as orphaned, even when files exist")
func emptyCurrentIdsNeverOrphansExistingFiles() {
// Regression test: this is the exact shape of the production bug. A fresh clone (or any
// moment where the local DB hasn't caught up yet) has zero local conversations, while the
// sync repo still has every previously-synced file on disk. Without the guard, all of them
// used to be flagged orphaned and deleted+pushed, wiping the whole sync repo.
let files = [
(filename: "a.md", markdown: makeExportMarkdown(id: UUID().uuidString)),
(filename: "b.md", markdown: makeExportMarkdown(id: UUID().uuidString)),
]
let orphans = GitSyncService.orphanedExportFilenames(currentIds: [], files: files)
#expect(orphans.isEmpty)
}
}