mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
fix accepting local and remote content during merge
This commit is contained in:
parent
bf9cc76621
commit
a8b2444df1
|
@ -177,42 +177,58 @@ 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> {
|
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
|
||||||
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
|
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
|
||||||
|
|
||||||
if (content !== null) {
|
if (localChange === Change.None && remoteChange === Change.None) {
|
||||||
if (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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localChange !== Change.None) {
|
|
||||||
this.logService.trace(`${this.syncResourceLogLabel}: Updating local keybindings...`);
|
|
||||||
if (fileContent) {
|
|
||||||
await this.backupLocal(this.toSyncContent(fileContent.value.toString(), null));
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
|
|
||||||
this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the preview
|
|
||||||
try {
|
|
||||||
await this.fileService.del(this.previewResource);
|
|
||||||
} catch (e) { /* ignore */ }
|
|
||||||
} else {
|
|
||||||
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localChange !== Change.None) {
|
||||||
|
this.logService.trace(`${this.syncResourceLogLabel}: Updating local keybindings...`);
|
||||||
|
if (fileContent) {
|
||||||
|
await this.backupLocal(this.toSyncContent(fileContent.value.toString(), null));
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
|
||||||
|
this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the preview
|
||||||
|
try {
|
||||||
|
await this.fileService.del(this.previewResource);
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
if (lastSyncUserData?.ref !== remoteUserData.ref) {
|
if (lastSyncUserData?.ref !== remoteUserData.ref) {
|
||||||
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized keybindings...`);
|
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;
|
const lastSyncContent = content !== null ? this.toSyncContent(content, null) : null;
|
||||||
await this.updateLastSyncUserData({ ref: remoteUserData.ref, syncData: lastSyncContent ? { version: remoteUserData.syncData!.version, machineId: remoteUserData.syncData!.machineId, content: lastSyncContent } : 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`);
|
this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized keybindings`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
|
||||||
previewContent,
|
previewContent,
|
||||||
acceptedResource: this.acceptedResource,
|
acceptedResource: this.acceptedResource,
|
||||||
acceptedContent,
|
acceptedContent,
|
||||||
localChange: hasLocalChanged ? fileContent ? Change.Modified : Change.Added : Change.None,
|
localChange: hasLocalChanged ? Change.Modified : Change.None,
|
||||||
remoteChange: hasRemoteChanged ? Change.Modified : Change.None,
|
remoteChange: hasRemoteChanged ? Change.Modified : Change.None,
|
||||||
hasConflicts,
|
hasConflicts,
|
||||||
}];
|
}];
|
||||||
|
@ -206,43 +206,49 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
|
||||||
const ignoredSettings = await this.getIgnoredSettings();
|
const ignoredSettings = await this.getIgnoredSettings();
|
||||||
acceptedContent = updateIgnoredSettings(acceptedContent, resourcePreview.fileContent ? resourcePreview.fileContent.value.toString() : '{}', ignoredSettings, formatUtils);
|
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> {
|
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
|
||||||
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
|
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
|
||||||
|
|
||||||
if (content !== null) {
|
if (localChange === Change.None && remoteChange === Change.None) {
|
||||||
|
|
||||||
this.validateContent(content);
|
|
||||||
|
|
||||||
if (localChange !== Change.None) {
|
|
||||||
this.logService.trace(`${this.syncResourceLogLabel}: Updating local settings...`);
|
|
||||||
if (fileContent) {
|
|
||||||
await this.backupLocal(JSON.stringify(this.toSettingsSyncContent(fileContent.value.toString())));
|
|
||||||
}
|
|
||||||
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
|
|
||||||
const remoteSettingsSyncContent = this.getSettingsSyncContent(remoteUserData);
|
|
||||||
const ignoredSettings = await this.getIgnoredSettings(content);
|
|
||||||
content = updateIgnoredSettings(content, remoteSettingsSyncContent ? remoteSettingsSyncContent.settings : '{}', ignoredSettings, formatUtils);
|
|
||||||
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote settings...`);
|
|
||||||
remoteUserData = await this.updateRemoteUserData(JSON.stringify(this.toSettingsSyncContent(content)), force ? null : remoteUserData.ref);
|
|
||||||
this.logService.info(`${this.syncResourceLogLabel}: Updated remote settings`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the preview
|
|
||||||
try {
|
|
||||||
await this.fileService.del(this.previewResource);
|
|
||||||
} catch (e) { /* ignore */ }
|
|
||||||
} else {
|
|
||||||
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
|
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content = content !== null ? content : '{}';
|
||||||
|
this.validateContent(content);
|
||||||
|
|
||||||
|
if (localChange !== Change.None) {
|
||||||
|
this.logService.trace(`${this.syncResourceLogLabel}: Updating local settings...`);
|
||||||
|
if (fileContent) {
|
||||||
|
await this.backupLocal(JSON.stringify(this.toSettingsSyncContent(fileContent.value.toString())));
|
||||||
|
}
|
||||||
|
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
|
||||||
|
const remoteSettingsSyncContent = this.getSettingsSyncContent(remoteUserData);
|
||||||
|
const ignoredSettings = await this.getIgnoredSettings(content);
|
||||||
|
content = updateIgnoredSettings(content, remoteSettingsSyncContent ? remoteSettingsSyncContent.settings : '{}', ignoredSettings, formatUtils);
|
||||||
|
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote settings...`);
|
||||||
|
remoteUserData = await this.updateRemoteUserData(JSON.stringify(this.toSettingsSyncContent(content)), force ? null : remoteUserData.ref);
|
||||||
|
this.logService.info(`${this.syncResourceLogLabel}: Updated remote settings`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the preview
|
||||||
|
try {
|
||||||
|
await this.fileService.del(this.previewResource);
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
if (lastSyncUserData?.ref !== remoteUserData.ref) {
|
if (lastSyncUserData?.ref !== remoteUserData.ref) {
|
||||||
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized settings...`);
|
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized settings...`);
|
||||||
await this.updateLastSyncUserData(remoteUserData);
|
await this.updateLastSyncUserData(remoteUserData);
|
||||||
|
|
Loading…
Reference in a new issue