Skip to content

Commit 6b4844e

Browse files
committed
Fixed current branch and branch listing
1 parent 3a54af7 commit 6b4844e

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/svnRepository.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,37 @@ export class Repository {
5555
}
5656

5757
async getCurrentBranch(): Promise<string> {
58-
try {
59-
const result = await this.svn.info(this.workspaceRoot);
60-
const currentBranch = result.stdout
61-
.match(/<url>(.*?)<\/url>/)[1]
62-
.split("/")
63-
.pop();
64-
return currentBranch;
65-
} catch (error) {
66-
console.error(error);
58+
const info = await this.svn.info(this.workspaceRoot);
59+
60+
if (info.exitCode !== 0) {
61+
throw new Error(info.stderr);
62+
}
63+
64+
const config = workspace.getConfiguration("svn");
65+
const trunkLayout = config.get<string>("layout.trunk");
66+
const branchesLayout = config.get<string>("layout.branches");
67+
const tagsLayout = config.get<string>("layout.tags");
68+
69+
const trees = [trunkLayout, branchesLayout, tagsLayout].filter(
70+
x => x != null
71+
);
72+
const regex = new RegExp(
73+
"<url>(.*?)/(" + trees.join("|") + ")(/([^/]+))?.*?</url>"
74+
);
75+
76+
const match = info.stdout.match(regex);
77+
78+
if (match) {
79+
if (match[4] && match[2] !== trunkLayout) {
80+
return match[4];
81+
}
82+
if (match[2]) {
83+
return match[2];
84+
}
85+
}
86+
6787
return "";
6888
}
69-
}
7089

7190
async getRepoUrl() {
7291
const config = workspace.getConfiguration("svn");
@@ -136,10 +155,9 @@ export class Repository {
136155
trees.push(tagsLayout);
137156
}
138157

139-
for (let index in trees) {
158+
for (const tree of trees) {
140159
promises.push(
141160
new Promise<string[]>(async resolve => {
142-
const tree = trees[index];
143161
const branchUrl = repoUrl + "/" + tree;
144162

145163
const result = await this.svn.list(branchUrl);
@@ -153,6 +171,7 @@ export class Repository {
153171
.trim()
154172
.replace(/\/|\\/g, "")
155173
.split(/[\r\n]+/)
174+
.filter((x: string) => !!x)
156175
.map((i: string) => tree + "/" + i);
157176

158177
resolve(list);

0 commit comments

Comments
 (0)