diff --git a/src/settings/settings.ts b/src/settings/settings.ts index e1da5d5..17346c7 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -8,7 +8,7 @@ export interface GitHubSyncSettings { syncInterval: number; syncOnStartup: boolean; syncConfigDir: boolean; - conflictHandling: "ignore" | "ask" | "overwrite"; + conflictHandling: "overwriteLocal" | "ask" | "overwriteRemote"; showStatusBarItem: boolean; showSyncRibbonButton: boolean; showConflictsRibbonButton: boolean; @@ -25,7 +25,7 @@ export const DEFAULT_SETTINGS: GitHubSyncSettings = { syncInterval: 1, syncOnStartup: false, syncConfigDir: true, - conflictHandling: "overwrite", + conflictHandling: "ask", showStatusBarItem: true, showSyncRibbonButton: true, showConflictsRibbonButton: true, diff --git a/src/settings/tab.ts b/src/settings/tab.ts index da4ca76..79c6161 100644 --- a/src/settings/tab.ts +++ b/src/settings/tab.ts @@ -163,16 +163,15 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab { }); const conflictHandlingOptions = { - ignore: "Ignore remote file", + overwriteLocal: "Overwrite local file", ask: "Ask", - overwrite: "Overwrite local file", + overwriteRemote: "Overwrite remote file", }; new Setting(containerEl) .setName("Conflict handling") .setDesc( `What to do in case remote and local files conflict - when downloading from GitHub repository - `, + when downloading from GitHub repository`, ) .addDropdown((dropdown) => { dropdown @@ -182,8 +181,7 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab { this.plugin.settings.conflictHandling = value; await this.plugin.saveSettings(); }); - }) - .setDisabled(true); + }); containerEl.createEl("h2", { text: "Interface" }); diff --git a/src/sync-manager.ts b/src/sync-manager.ts index 0efaef0..71ddee5 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -328,13 +328,37 @@ export default class SyncManager { if (conflicts.length > 0) { await this.logger.warn("Found conflicts", conflicts); - // Here we block the sync process until the user has resolved all the conflicts - conflictResolutions = await this.onConflicts(conflicts); - conflictActions = conflictResolutions.map( - (resolution: ConflictResolution) => { - return { type: "upload", filePath: resolution.filePath }; - }, - ); + if (this.settings.conflictHandling === "ask") { + // Here we block the sync process until the user has resolved all the conflicts + conflictResolutions = await this.onConflicts(conflicts); + conflictActions = conflictResolutions.map( + (resolution: ConflictResolution) => { + return { type: "upload", filePath: resolution.filePath }; + }, + ); + } else if (this.settings.conflictHandling === "overwriteLocal") { + // The user explicitly wants to always overwrite the local file + // in case of conflicts so we just download the remote file to solve it + + // It's not necessary to set conflict resolutions as the content the + // user expect must be the content of the remote file with no changes. + conflictActions = conflictResolutions.map( + (resolution: ConflictResolution) => { + return { type: "download", filePath: resolution.filePath }; + }, + ); + } else if (this.settings.conflictHandling === "overwriteRemote") { + // The user explicitly wants to always overwrite the remote file + // in case of conflicts so we just upload the remote file to solve it. + + // It's not necessary to set conflict resolutions as the content the + // user expect must be the content of the local file with no changes. + conflictActions = conflictResolutions.map( + (resolution: ConflictResolution) => { + return { type: "upload", filePath: resolution.filePath }; + }, + ); + } } const actions: SyncAction[] = [