Skip to content

Commit 87060b3

Browse files
authored
feat: Added Merge command (#1540)
1 parent 00f273f commit 87060b3

File tree

8 files changed

+114
-1
lines changed

8 files changed

+114
-1
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@
456456
"title": "Switch Branch",
457457
"category": "SVN"
458458
},
459+
{
460+
"command": "svn.merge",
461+
"title": "Merge",
462+
"category": "SVN"
463+
},
459464
{
460465
"command": "svn.treeview.pullIncomingChange",
461466
"title": "Update selected",
@@ -686,6 +691,10 @@
686691
"command": "svn.switchBranch",
687692
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
688693
},
694+
{
695+
"command": "svn.merge",
696+
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
697+
},
689698
{
690699
"command": "svn.treeview.pullIncomingChange",
691700
"when": "false"
@@ -814,6 +823,10 @@
814823
"command": "svn.switchBranch",
815824
"when": "config.svn.enabled && scmProvider == svn"
816825
},
826+
{
827+
"command": "svn.merge",
828+
"when": "config.svn.enabled && scmProvider == svn"
829+
},
817830
{
818831
"command": "svn.update",
819832
"when": "config.svn.enabled && scmProvider == svn"

src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { Upgrade } from "./commands/upgrade";
4545
import { SourceControlManager } from "./source_control_manager";
4646
import { SearchLogByRevision } from "./commands/search_log_by_revision";
4747
import { SearchLogByText } from "./commands/search_log_by_text";
48+
import { Merge } from "./commands/merge";
4849

4950
export function registerCommands(
5051
sourceControlManager: SourceControlManager,
@@ -63,6 +64,7 @@ export function registerCommands(
6364
disposables.push(new OpenResourceHead());
6465
disposables.push(new OpenChangeBase());
6566
disposables.push(new SwitchBranch());
67+
disposables.push(new Merge());
6668
disposables.push(new Revert());
6769
disposables.push(new Update());
6870
disposables.push(new PullIncommingChange());

src/commands/merge.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { commands, window } from "vscode";
2+
import { IBranchItem } from "../common/types";
3+
import { isTrunk, selectBranch } from "../helpers/branch";
4+
import { Repository } from "../repository";
5+
import { Command } from "./command";
6+
7+
export class Merge extends Command {
8+
constructor() {
9+
super("svn.merge", { repository: true });
10+
}
11+
12+
public async execute(repository: Repository) {
13+
const branch = await selectBranch(repository);
14+
15+
if (!branch) {
16+
return;
17+
}
18+
19+
await this.merge(repository, branch);
20+
}
21+
22+
async merge(repository: Repository, branch: IBranchItem) {
23+
let reintegrate = false;
24+
if (isTrunk(repository.currentBranch)) {
25+
reintegrate = true;
26+
}
27+
28+
try {
29+
await repository.merge(branch.path, reintegrate);
30+
} catch (error) {
31+
if (typeof error === "object" && error.hasOwnProperty("stderrFormated")) {
32+
if (error.stderrFormated.includes("try updating first")) {
33+
const answer = await window.showErrorMessage(
34+
"Seems like you need to update first prior to merging. " +
35+
"Would you like to update now and try merging again?",
36+
"Yes",
37+
"No"
38+
);
39+
if (answer === "Yes") {
40+
await commands.executeCommand("svn.update");
41+
await this.merge(repository, branch);
42+
}
43+
} else {
44+
window.showErrorMessage(
45+
"Unable to merge branch: " + error.stderrFormated
46+
);
47+
}
48+
} else {
49+
console.log(error);
50+
window.showErrorMessage("Unable to merge branch");
51+
}
52+
}
53+
}
54+
}

src/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export enum Operation {
110110
Info = "Info",
111111
Ignore = "Ignore",
112112
Log = "Log",
113+
Merge = "Merge",
113114
NewBranch = "NewBranch",
114115
Patch = "Patch",
115116
Remove = "Remove",

src/helpers/branch.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,16 @@ export async function selectBranch(
107107

108108
return;
109109
}
110+
111+
export function isTrunk(folder: string): boolean {
112+
const conf = "layout.trunkRegex";
113+
const layout = configuration.get<string>(conf);
114+
const regex = new RegExp(`(^|/)(${layout})$`);
115+
const matches = folder.match(regex);
116+
const group = configuration.get<number>(`${conf}Name`, 1) + 2;
117+
118+
if (matches && matches[2] && matches[group]) {
119+
return true;
120+
}
121+
return false;
122+
}

src/repository.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,17 @@ export class Repository implements IRemoteRepository {
817817
});
818818
}
819819

820+
public async merge(
821+
name: string,
822+
reintegrate: boolean = false,
823+
accept_action: string = "postpone"
824+
) {
825+
await this.run(Operation.Merge, async () => {
826+
await this.repository.merge(name, reintegrate, accept_action);
827+
this.updateRemoteChangedFiles();
828+
});
829+
}
830+
820831
public async updateRevision(
821832
ignoreExternals: boolean = false
822833
): Promise<string> {

src/statusbar/syncStatusBar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export class SyncStatusBar {
5050
const isSyncRunning =
5151
this.repository.operations.isRunning(Operation.SwitchBranch) ||
5252
this.repository.operations.isRunning(Operation.NewBranch) ||
53-
this.repository.operations.isRunning(Operation.Update);
53+
this.repository.operations.isRunning(Operation.Update) ||
54+
this.repository.operations.isRunning(Operation.Merge);
5455

5556
const isStatusRemoteRunning = this.repository.operations.isRunning(
5657
Operation.StatusRemote

src/svnRepository.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,24 @@ export class Repository {
662662
return true;
663663
}
664664

665+
public async merge(
666+
ref: string,
667+
reintegrate: boolean = false,
668+
accept_action: string = "postpone"
669+
) {
670+
const repoUrl = await this.getRepoUrl();
671+
const branchUrl = repoUrl + "/" + ref;
672+
673+
let args = ["merge", "--accept", accept_action];
674+
args = args.concat(reintegrate ? ["--reintegrate"] : []);
675+
args = args.concat([branchUrl]);
676+
677+
await this.exec(args);
678+
679+
this.resetInfoCache();
680+
return true;
681+
}
682+
665683
public async revert(files: string[], depth: keyof typeof SvnDepth) {
666684
files = files.map(file => this.removeAbsolutePath(file));
667685
const result = await this.exec(["revert", "--depth", depth, ...files]);

0 commit comments

Comments
 (0)