fix accepting local and remote content during merge

This commit is contained in:
Sandeep Somavarapu 2020-07-24 13:40:10 +02:00
parent bf9cc76621
commit a8b2444df1
2 changed files with 80 additions and 58 deletions

View file

@ -177,11 +177,23 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
}];
}
protected async updateResourcePreview(resourcePreview: IFileResourcePreview, resource: URI, acceptedContent: string | null): Promise<IFileResourcePreview> {
return {
...resourcePreview,
acceptedContent,
localChange: isEqual(resource, this.localResource) ? Change.None : Change.Modified,
remoteChange: isEqual(resource, this.remoteResource) ? Change.None : Change.Modified,
};
}
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
if (content !== null) {
if (this.hasErrors(content)) {
if (localChange === Change.None && remoteChange === Change.None) {
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
}
if (content !== null && this.hasErrors(content)) {
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync keybindings because the content in the file is not valid. Please open the file and correct it."), UserDataSyncErrorCode.LocalInvalidContent, this.resource);
}
@ -190,13 +202,13 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
if (fileContent) {
await this.backupLocal(this.toSyncContent(fileContent.value.toString(), null));
}
await this.updateLocalFileContent(content, fileContent, force);
await this.updateLocalFileContent(content || '[]', fileContent, force);
this.logService.info(`${this.syncResourceLogLabel}: Updated local keybindings`);
}
if (remoteChange !== Change.None) {
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote keybindings...`);
const remoteContents = this.toSyncContent(content, remoteUserData.syncData ? remoteUserData.syncData.content : null);
const remoteContents = this.toSyncContent(content || '[]', remoteUserData.syncData ? remoteUserData.syncData.content : null);
remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
}
@ -205,14 +217,18 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
try {
await this.fileService.del(this.previewResource);
} catch (e) { /* ignore */ }
} else {
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
}
if (lastSyncUserData?.ref !== remoteUserData.ref) {
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized keybindings...`);
const lastSyncContent = content !== null || fileContent !== null ? this.toSyncContent(content !== null ? content : fileContent!.value.toString(), null) : null;
await this.updateLastSyncUserData({ ref: remoteUserData.ref, syncData: lastSyncContent ? { version: remoteUserData.syncData!.version, machineId: remoteUserData.syncData!.machineId, content: lastSyncContent } : null });
const lastSyncContent = content !== null ? this.toSyncContent(content, null) : null;
await this.updateLastSyncUserData({
ref: remoteUserData.ref,
syncData: lastSyncContent ? {
version: remoteUserData.syncData ? remoteUserData.syncData.version : this.version,
machineId: remoteUserData.syncData!.machineId,
content: lastSyncContent
} : null
});
this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized keybindings`);
}

View file

@ -193,7 +193,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
previewContent,
acceptedResource: this.acceptedResource,
acceptedContent,
localChange: hasLocalChanged ? fileContent ? Change.Modified : Change.Added : Change.None,
localChange: hasLocalChanged ? Change.Modified : Change.None,
remoteChange: hasRemoteChanged ? Change.Modified : Change.None,
hasConflicts,
}];
@ -206,14 +206,22 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
const ignoredSettings = await this.getIgnoredSettings();
acceptedContent = updateIgnoredSettings(acceptedContent, resourcePreview.fileContent ? resourcePreview.fileContent.value.toString() : '{}', ignoredSettings, formatUtils);
}
return super.updateResourcePreview(resourcePreview, resource, acceptedContent) as Promise<IFileResourcePreview>;
return {
...resourcePreview,
acceptedContent,
localChange: isEqual(resource, this.localResource) ? Change.None : Change.Modified,
remoteChange: isEqual(resource, this.remoteResource) ? Change.None : Change.Modified,
};
}
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
if (content !== null) {
if (localChange === Change.None && remoteChange === Change.None) {
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
}
content = content !== null ? content : '{}';
this.validateContent(content);
if (localChange !== Change.None) {
@ -224,6 +232,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
await this.updateLocalFileContent(content, fileContent, force);
this.logService.info(`${this.syncResourceLogLabel}: Updated local settings`);
}
if (remoteChange !== Change.None) {
const formatUtils = await this.getFormattingOptions();
// Update ignored settings from remote
@ -239,9 +248,6 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
try {
await this.fileService.del(this.previewResource);
} catch (e) { /* ignore */ }
} else {
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
}
if (lastSyncUserData?.ref !== remoteUserData.ref) {
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized settings...`);