mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Respect user settings on conflict
This commit is contained in:
parent
7bca8262f4
commit
0ca42124db
3 changed files with 37 additions and 15 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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" });
|
||||
|
||||
|
|
|
|||
|
|
@ -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[] = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue