Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hediet/september #159654

Merged
merged 7 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"scmSelectedProvider",
"scmValidation",
"tabInputTextMerge",
"timeline"
"timeline",
"mergeEditorMenus"
],
"categories": [
"Other"
Expand Down Expand Up @@ -609,6 +610,18 @@
"command": "git.openMergeEditor",
"title": "%command.git.openMergeEditor%",
"category": "Git"
},
{
"command": "git.runGitMerge",
"title": "%command.git.runGitMerge%",
"category": "Git",
"enablement": "isMergeEditor"
},
{
"command": "git.runGitMergeDiff3",
"title": "%command.git.runGitMergeDiff3%",
"category": "Git",
"enablement": "isMergeEditor"
}
],
"keybindings": [
Expand Down Expand Up @@ -1568,6 +1581,16 @@
"when": "config.git.enabled && !git.missing && !isInDiffEditor && !isMergeEditor && resource in git.mergeChanges"
}
],
"mergeEditor/result/title": [
{
"command": "git.runGitMerge",
"when": "isMergeEditor"
},
{
"command": "git.runGitMergeDiff3",
"when": "isMergeEditor"
}
],
"scm/change/title": [
{
"command": "git.stageChange",
Expand Down
2 changes: 2 additions & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
"command.api.getRemoteSources": "Get Remote Sources",
"command.git.acceptMerge": "Accept Merge",
"command.git.openMergeEditor": "Open in Merge Editor",
"command.git.runGitMerge": "Compute Conflicts With Git",
"command.git.runGitMergeDiff3": "Compute Conflicts With Git (Diff3)",
"config.enabled": "Whether git is enabled.",
"config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows). This can also be an array of string values containing multiple paths to look up.",
"config.autoRepositoryDetection": "Configures when repositories should be automatically detected.",
Expand Down
45 changes: 45 additions & 0 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,51 @@ 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) {
hediet marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const input = activeTab.input;
if (!(input instanceof TabInputTextMerge)) {
return;
}

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;
Expand Down
21 changes: 21 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class MenuId {
static readonly NewFile = new MenuId('NewFile');
static readonly MergeInput1Toolbar = new MenuId('MergeToolbar1Toolbar');
static readonly MergeInput2Toolbar = new MenuId('MergeToolbar2Toolbar');
static readonly MergeInputResultToolbar = new MenuId('MergeToolbarResultToolbar');

/**
* Create or reuse a `MenuId` with the given identifier
Expand Down
48 changes: 48 additions & 0 deletions src/vs/workbench/contrib/mergeEditor/browser/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,51 @@ export class AcceptAllInput2 extends MergeEditorAction {
viewModel.acceptAll(2);
}
}

export class ResetToBaseAndAutoMergeCommand extends MergeEditorAction {
constructor() {
super({
id: 'mergeEditor.resetResultToBaseAndAutoMerge',
category: mergeEditorCategory,
title: {
value: localize(
'mergeEditor.resetResultToBaseAndAutoMerge',
'Reset Result'
),
original: 'Reset Result',
},
shortTitle: localize('mergeEditor.resetResultToBaseAndAutoMerge.short', 'Reset'),
f1: true,
precondition: ctxIsMergeEditor,
menu: { id: MenuId.MergeInputResultToolbar }
});
}

override runWithViewModel(viewModel: MergeEditorViewModel, accessor: ServicesAccessor): void {
viewModel.model.resetResultToBaseAndAutoMerge();
}
}

export class ResetDirtyConflictsToBaseCommand extends MergeEditorAction {
constructor() {
super({
id: 'mergeEditor.resetDirtyConflictsToBase',
category: mergeEditorCategory,
title: {
value: localize(
'mergeEditor.resetDirtyConflictsToBase',
'Reset Dirty Conflicts In Result To Base'
),
original: 'Reset Dirty Conflicts In Result To Base',
},
shortTitle: localize('mergeEditor.resetDirtyConflictsToBase.short', 'Reset Dirty Conflicts To Base'),
f1: true,
precondition: ctxIsMergeEditor,
menu: { id: MenuId.MergeInputResultToolbar }
});
}

override runWithViewModel(viewModel: MergeEditorViewModel, accessor: ServicesAccessor): void {
viewModel.model.resetDirtyConflictsToBase();
}
}