mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Implements commands to recompute merge with git merge-file
This commit is contained in:
@@ -1134,6 +1134,48 @@ export class CommandCenter {
|
||||
}
|
||||
}
|
||||
|
||||
@command('git.runGitMerge')
|
||||
async runGitMergeNoDiff3(): Promise<void> {
|
||||
await this.runGitMerge(false);
|
||||
}
|
||||
|
||||
@command('git.runGitMergeDiff3')
|
||||
async runGitMergeDiff3(): Promise<void> {
|
||||
await this.runGitMerge(true);
|
||||
}
|
||||
|
||||
private async runGitMerge(diff3: boolean): Promise<void> {
|
||||
const { activeTab } = window.tabGroups.activeTabGroup;
|
||||
if (!activeTab) {
|
||||
return;
|
||||
}
|
||||
|
||||
const input = activeTab.input as { base: Uri; input1: Uri; input2: Uri; result: Uri };
|
||||
|
||||
const result = await this.git.mergeFile({
|
||||
basePath: input.base.fsPath,
|
||||
input1Path: input.input1.fsPath,
|
||||
input2Path: input.input2.fsPath,
|
||||
diff3,
|
||||
});
|
||||
|
||||
const doc = workspace.textDocuments.find(doc => doc.uri.toString() === input.result.toString());
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
const e = new WorkspaceEdit();
|
||||
|
||||
e.replace(
|
||||
input.result,
|
||||
new Range(
|
||||
new Position(0, 0),
|
||||
new Position(doc.lineCount, 0),
|
||||
),
|
||||
result
|
||||
);
|
||||
await workspace.applyEdit(e);
|
||||
}
|
||||
|
||||
private async _stageChanges(textEditor: TextEditor, changes: LineChange[]): Promise<void> {
|
||||
const modifiedDocument = textEditor.document;
|
||||
const modifiedUri = modifiedDocument.uri;
|
||||
|
||||
@@ -656,6 +656,27 @@ export class Git {
|
||||
private log(output: string): void {
|
||||
this._onOutput.emit('log', output);
|
||||
}
|
||||
|
||||
async mergeFile(options: { input1Path: string; input2Path: string; basePath: string; diff3?: boolean }): Promise<string> {
|
||||
const args = ['merge-file', '-p', options.input1Path, options.basePath, options.input2Path];
|
||||
if (options.diff3) {
|
||||
args.push('--diff3');
|
||||
} else {
|
||||
args.push('--no-diff3');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.exec('', args);
|
||||
return result.stdout;
|
||||
} catch (err) {
|
||||
if (typeof err.stdout === 'string') {
|
||||
// The merge had conflicts, stdout still contains the merged result (with conflict markers)
|
||||
return err.stdout;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface Commit {
|
||||
|
||||
Reference in New Issue
Block a user