Skip to content

Commit

Permalink
Save resolved text file from merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
navn-r committed Aug 18, 2021
1 parent 7078a87 commit 88f7176
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/commandsAndMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function addCommands(
settings: ISettingRegistry.ISettings,
trans: TranslationBundle
): void {
const { commands, shell } = app;
const { commands, shell, serviceManager } = app;

/**
* Commit using a keystroke combination when in CommitBox.
Expand Down Expand Up @@ -487,10 +487,20 @@ export function addCommands(
onClick: async () => {
try {
const resolvedFile: string = await widget.getResolvedFile();
// TODO update the file without the conflicts, then close the tab
console.log(resolvedFile);
await serviceManager.contents.save(model.filename, {
type: 'file',
format: 'text',
content: resolvedFile
});
await gitModel.add(model.filename);
await gitModel.refresh();
} catch (reason) {
console.error(reason);
logger.log({
message: reason.message ?? reason,
level: Level.ERROR
});
} finally {
diffWidget.dispose();
}
},
tooltip: trans.__('Mark file as resolved'),
Expand All @@ -517,7 +527,7 @@ export function addCommands(
content.addWidget(widget);
} catch (reason) {
console.error(reason);
const msg = `Load Diff Model Error (${reason.message || reason})`;
const msg = `Load Diff Model Error (${reason.message ?? reason})`;
modelIsLoading.reject(msg);
}
}
Expand Down Expand Up @@ -598,8 +608,8 @@ export function addCommands(
const diffContext: Git.Diff.IContext =
status === 'unmerged'
? {
currentRef: 'MERGE_HEAD',
previousRef: 'HEAD',
currentRef: 'HEAD',
previousRef: 'MERGE_HEAD',
baseRef: 'ORIG_HEAD'
}
: context ?? {
Expand All @@ -612,7 +622,7 @@ export function addCommands(
: { git: diffContext.currentRef };

// Base props used for Diff Model
const props = {
const props: Omit<Git.Diff.IModel<string>, 'changed' | 'isConflict'> = {
challenger: {
content: async () => {
return requestAPI<Git.IDiffContent>(
Expand Down Expand Up @@ -647,9 +657,15 @@ export function addCommands(
diffContext.previousRef,
source: diffContext.previousRef,
updateAt: Date.now()
},
}
};

if (diffContext.baseRef) {
props.reference.label = trans.__('CURRENT');
props.challenger.label = trans.__('INCOMING');

// Only add base when diff-ing merge conflicts
base: diffContext.baseRef && {
props.base = {
content: async () => {
return requestAPI<Git.IDiffContent>(
URLExt.join(repositoryPath, 'content'),
Expand All @@ -660,13 +676,11 @@ export function addCommands(
}
).then(data => data.content);
},
label:
(Git.Diff.SpecialRef[diffContext.baseRef as any] as any) ||
diffContext.baseRef,
label: trans.__('RESULT'),
source: diffContext.baseRef,
updateAt: Date.now()
}
};
};
}

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

0 comments on commit 88f7176

Please sign in to comment.