Skip to content

Commit a8b2444

Browse files
committed
fix accepting local and remote content during merge
1 parent bf9cc76 commit a8b2444

File tree

2 files changed

+74
-52
lines changed

2 files changed

+74
-52
lines changed

src/vs/platform/userDataSync/common/keybindingsSync.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,42 +177,58 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
177177
}];
178178
}
179179

180+
protected async updateResourcePreview(resourcePreview: IFileResourcePreview, resource: URI, acceptedContent: string | null): Promise<IFileResourcePreview> {
181+
return {
182+
...resourcePreview,
183+
acceptedContent,
184+
localChange: isEqual(resource, this.localResource) ? Change.None : Change.Modified,
185+
remoteChange: isEqual(resource, this.remoteResource) ? Change.None : Change.Modified,
186+
};
187+
}
188+
180189
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
181190
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
182191

183-
if (content !== null) {
184-
if (this.hasErrors(content)) {
185-
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);
186-
}
192+
if (localChange === Change.None && remoteChange === Change.None) {
193+
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
194+
}
187195

188-
if (localChange !== Change.None) {
189-
this.logService.trace(`${this.syncResourceLogLabel}: Updating local keybindings...`);
190-
if (fileContent) {
191-
await this.backupLocal(this.toSyncContent(fileContent.value.toString(), null));
192-
}
193-
await this.updateLocalFileContent(content, fileContent, force);
194-
this.logService.info(`${this.syncResourceLogLabel}: Updated local keybindings`);
195-
}
196+
if (content !== null && this.hasErrors(content)) {
197+
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);
198+
}
196199

197-
if (remoteChange !== Change.None) {
198-
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote keybindings...`);
199-
const remoteContents = this.toSyncContent(content, remoteUserData.syncData ? remoteUserData.syncData.content : null);
200-
remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
201-
this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
200+
if (localChange !== Change.None) {
201+
this.logService.trace(`${this.syncResourceLogLabel}: Updating local keybindings...`);
202+
if (fileContent) {
203+
await this.backupLocal(this.toSyncContent(fileContent.value.toString(), null));
202204
}
205+
await this.updateLocalFileContent(content || '[]', fileContent, force);
206+
this.logService.info(`${this.syncResourceLogLabel}: Updated local keybindings`);
207+
}
203208

204-
// Delete the preview
205-
try {
206-
await this.fileService.del(this.previewResource);
207-
} catch (e) { /* ignore */ }
208-
} else {
209-
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
209+
if (remoteChange !== Change.None) {
210+
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote keybindings...`);
211+
const remoteContents = this.toSyncContent(content || '[]', remoteUserData.syncData ? remoteUserData.syncData.content : null);
212+
remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
213+
this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
210214
}
211215

216+
// Delete the preview
217+
try {
218+
await this.fileService.del(this.previewResource);
219+
} catch (e) { /* ignore */ }
220+
212221
if (lastSyncUserData?.ref !== remoteUserData.ref) {
213222
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized keybindings...`);
214-
const lastSyncContent = content !== null || fileContent !== null ? this.toSyncContent(content !== null ? content : fileContent!.value.toString(), null) : null;
215-
await this.updateLastSyncUserData({ ref: remoteUserData.ref, syncData: lastSyncContent ? { version: remoteUserData.syncData!.version, machineId: remoteUserData.syncData!.machineId, content: lastSyncContent } : null });
223+
const lastSyncContent = content !== null ? this.toSyncContent(content, null) : null;
224+
await this.updateLastSyncUserData({
225+
ref: remoteUserData.ref,
226+
syncData: lastSyncContent ? {
227+
version: remoteUserData.syncData ? remoteUserData.syncData.version : this.version,
228+
machineId: remoteUserData.syncData!.machineId,
229+
content: lastSyncContent
230+
} : null
231+
});
216232
this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized keybindings`);
217233
}
218234

src/vs/platform/userDataSync/common/settingsSync.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
193193
previewContent,
194194
acceptedResource: this.acceptedResource,
195195
acceptedContent,
196-
localChange: hasLocalChanged ? fileContent ? Change.Modified : Change.Added : Change.None,
196+
localChange: hasLocalChanged ? Change.Modified : Change.None,
197197
remoteChange: hasRemoteChanged ? Change.Modified : Change.None,
198198
hasConflicts,
199199
}];
@@ -206,43 +206,49 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
206206
const ignoredSettings = await this.getIgnoredSettings();
207207
acceptedContent = updateIgnoredSettings(acceptedContent, resourcePreview.fileContent ? resourcePreview.fileContent.value.toString() : '{}', ignoredSettings, formatUtils);
208208
}
209-
return super.updateResourcePreview(resourcePreview, resource, acceptedContent) as Promise<IFileResourcePreview>;
209+
return {
210+
...resourcePreview,
211+
acceptedContent,
212+
localChange: isEqual(resource, this.localResource) ? Change.None : Change.Modified,
213+
remoteChange: isEqual(resource, this.remoteResource) ? Change.None : Change.Modified,
214+
};
210215
}
211216

212217
protected async applyPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, resourcePreviews: IFileResourcePreview[], force: boolean): Promise<void> {
213218
let { fileContent, acceptedContent: content, localChange, remoteChange } = resourcePreviews[0];
214219

215-
if (content !== null) {
220+
if (localChange === Change.None && remoteChange === Change.None) {
221+
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
222+
}
216223

217-
this.validateContent(content);
224+
content = content !== null ? content : '{}';
225+
this.validateContent(content);
218226

219-
if (localChange !== Change.None) {
220-
this.logService.trace(`${this.syncResourceLogLabel}: Updating local settings...`);
221-
if (fileContent) {
222-
await this.backupLocal(JSON.stringify(this.toSettingsSyncContent(fileContent.value.toString())));
223-
}
224-
await this.updateLocalFileContent(content, fileContent, force);
225-
this.logService.info(`${this.syncResourceLogLabel}: Updated local settings`);
226-
}
227-
if (remoteChange !== Change.None) {
228-
const formatUtils = await this.getFormattingOptions();
229-
// Update ignored settings from remote
230-
const remoteSettingsSyncContent = this.getSettingsSyncContent(remoteUserData);
231-
const ignoredSettings = await this.getIgnoredSettings(content);
232-
content = updateIgnoredSettings(content, remoteSettingsSyncContent ? remoteSettingsSyncContent.settings : '{}', ignoredSettings, formatUtils);
233-
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote settings...`);
234-
remoteUserData = await this.updateRemoteUserData(JSON.stringify(this.toSettingsSyncContent(content)), force ? null : remoteUserData.ref);
235-
this.logService.info(`${this.syncResourceLogLabel}: Updated remote settings`);
227+
if (localChange !== Change.None) {
228+
this.logService.trace(`${this.syncResourceLogLabel}: Updating local settings...`);
229+
if (fileContent) {
230+
await this.backupLocal(JSON.stringify(this.toSettingsSyncContent(fileContent.value.toString())));
236231
}
232+
await this.updateLocalFileContent(content, fileContent, force);
233+
this.logService.info(`${this.syncResourceLogLabel}: Updated local settings`);
234+
}
237235

238-
// Delete the preview
239-
try {
240-
await this.fileService.del(this.previewResource);
241-
} catch (e) { /* ignore */ }
242-
} else {
243-
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing settings.`);
236+
if (remoteChange !== Change.None) {
237+
const formatUtils = await this.getFormattingOptions();
238+
// Update ignored settings from remote
239+
const remoteSettingsSyncContent = this.getSettingsSyncContent(remoteUserData);
240+
const ignoredSettings = await this.getIgnoredSettings(content);
241+
content = updateIgnoredSettings(content, remoteSettingsSyncContent ? remoteSettingsSyncContent.settings : '{}', ignoredSettings, formatUtils);
242+
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote settings...`);
243+
remoteUserData = await this.updateRemoteUserData(JSON.stringify(this.toSettingsSyncContent(content)), force ? null : remoteUserData.ref);
244+
this.logService.info(`${this.syncResourceLogLabel}: Updated remote settings`);
244245
}
245246

247+
// Delete the preview
248+
try {
249+
await this.fileService.del(this.previewResource);
250+
} catch (e) { /* ignore */ }
251+
246252
if (lastSyncUserData?.ref !== remoteUserData.ref) {
247253
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized settings...`);
248254
await this.updateLastSyncUserData(remoteUserData);

0 commit comments

Comments
 (0)