Skip to content

Commit 1f26e0d

Browse files
committed
Save resolved text file from merge conflict
1 parent 6282b4e commit 1f26e0d

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/commandsAndMenu.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function addCommands(
104104
settings: ISettingRegistry.ISettings,
105105
trans: TranslationBundle
106106
): void {
107-
const { commands, shell } = app;
107+
const { commands, shell, serviceManager } = app;
108108

109109
/**
110110
* Commit using a keystroke combination when in CommitBox.
@@ -486,10 +486,20 @@ export function addCommands(
486486
onClick: async () => {
487487
try {
488488
const resolvedFile: string = await widget.getResolvedFile();
489-
// TODO update the file without the conflicts, then close the tab
490-
console.log(resolvedFile);
489+
await serviceManager.contents.save(model.filename, {
490+
type: 'file',
491+
format: 'text',
492+
content: resolvedFile
493+
});
494+
await gitModel.add(model.filename);
495+
await gitModel.refresh();
491496
} catch (reason) {
492-
console.error(reason);
497+
logger.log({
498+
message: reason.message ?? reason,
499+
level: Level.ERROR
500+
});
501+
} finally {
502+
diffWidget.dispose();
493503
}
494504
},
495505
tooltip: trans.__('Mark file as resolved'),
@@ -516,7 +526,7 @@ export function addCommands(
516526
content.addWidget(widget);
517527
} catch (reason) {
518528
console.error(reason);
519-
const msg = `Load Diff Model Error (${reason.message || reason})`;
529+
const msg = `Load Diff Model Error (${reason.message ?? reason})`;
520530
modelIsLoading.reject(msg);
521531
}
522532
}
@@ -597,8 +607,8 @@ export function addCommands(
597607
const diffContext: Git.Diff.IContext =
598608
status === 'unmerged'
599609
? {
600-
currentRef: 'MERGE_HEAD',
601-
previousRef: 'HEAD',
610+
currentRef: 'HEAD',
611+
previousRef: 'MERGE_HEAD',
602612
baseRef: 'ORIG_HEAD'
603613
}
604614
: context ?? {
@@ -611,7 +621,7 @@ export function addCommands(
611621
: { git: diffContext.currentRef };
612622

613623
// Base props used for Diff Model
614-
const props = {
624+
const props: Omit<Git.Diff.IModel<string>, 'changed' | 'isConflict'> = {
615625
challenger: {
616626
content: async () => {
617627
return requestAPI<Git.IDiffContent>(
@@ -646,9 +656,15 @@ export function addCommands(
646656
diffContext.previousRef,
647657
source: diffContext.previousRef,
648658
updateAt: Date.now()
649-
},
659+
}
660+
};
661+
662+
if (diffContext.baseRef) {
663+
props.reference.label = trans.__('CURRENT');
664+
props.challenger.label = trans.__('INCOMING');
665+
650666
// Only add base when diff-ing merge conflicts
651-
base: diffContext.baseRef && {
667+
props.base = {
652668
content: async () => {
653669
return requestAPI<Git.IDiffContent>(
654670
URLExt.join(repositoryPath, 'content'),
@@ -659,13 +675,11 @@ export function addCommands(
659675
}
660676
).then(data => data.content);
661677
},
662-
label:
663-
(Git.Diff.SpecialRef[diffContext.baseRef as any] as any) ||
664-
diffContext.baseRef,
678+
label: trans.__('RESULT'),
665679
source: diffContext.baseRef,
666680
updateAt: Date.now()
667-
}
668-
};
681+
};
682+
}
669683

670684
// Create the diff widget
671685
const model = new DiffModel<string>(props);

0 commit comments

Comments
 (0)