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:
@@ -68,6 +68,11 @@ class GitSyncService {
|
||||
_ = try await runGit(["clone", url, localPath])
|
||||
syncStatus.isCloned = true
|
||||
|
||||
// Import immediately so this machine's DB is never left empty after a clone —
|
||||
// an empty DB is what makes the next export think every existing conversation
|
||||
// was deleted (see exportAllConversations's orphan-cleanup guard).
|
||||
_ = try? await importAllConversations()
|
||||
|
||||
await updateStatus()
|
||||
}
|
||||
|
||||
@@ -202,7 +207,15 @@ class GitSyncService {
|
||||
currentIds: Set<String>,
|
||||
files: [(filename: String, markdown: String)]
|
||||
) -> [String] {
|
||||
files.compactMap { file in
|
||||
// A locally-empty conversation list is indistinguishable here from "nothing has been
|
||||
// imported into this machine's DB yet" (e.g. right after a fresh clone). Treating it as
|
||||
// "every existing file was deleted" wiped a user's entire sync repo in production: clone
|
||||
// completed, an auto-sync fired before the post-clone import finished, every synced
|
||||
// conversation looked orphaned, and the deletion got committed and pushed. Skipping
|
||||
// cleanup here means a genuine last-conversation deletion won't propagate until another
|
||||
// conversation exists locally — a far smaller cost than mass data loss.
|
||||
guard !currentIds.isEmpty else { return [] }
|
||||
return files.compactMap { file in
|
||||
guard let export = try? ConversationExport.fromMarkdown(file.markdown) else { return nil }
|
||||
return currentIds.contains(export.id) ? nil : file.filename
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user