Skip to content

Commit 8e807ca

Browse files
authored
Merge pull request #39 from edgardmessias/support_to_subpath
Added support to subpath for project, in switching branches
2 parents ea60baf + 8e0b109 commit 8e807ca

File tree

2 files changed

+61
-35
lines changed

2 files changed

+61
-35
lines changed

src/commands.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,26 @@ class CreateBranchItem implements QuickPickItem {
3535
}
3636

3737
class SwitchBranchItem implements QuickPickItem {
38-
constructor(protected ref: string) {}
38+
protected tree: string = "";
39+
protected name: string = "";
40+
41+
constructor(protected ref: string) {
42+
let parts = ref.split("/");
43+
if (parts[1]) {
44+
this.tree = parts[0];
45+
this.name = parts[1];
46+
} else {
47+
this.tree = "trunk";
48+
this.name = parts[0];
49+
}
50+
}
3951

4052
get label(): string {
41-
return this.ref;
53+
return this.name;
4254
}
4355

4456
get description(): string {
45-
return "";
57+
return this.tree;
4658
}
4759

4860
async run(repository: Repository): Promise<void> {

src/svn.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -186,38 +186,62 @@ export class Repository {
186186
}
187187
}
188188

189-
async getBranches() {
189+
async getRepoUrl() {
190190
const info = await this.svn.info(this.root);
191-
191+
192192
if (info.exitCode !== 0) {
193193
throw new Error(info.stderr);
194194
}
195195

196-
const repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
197-
const branchUrl = repoUrl + "/branches";
196+
let repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
197+
const match = info.stdout.match(/<url>(.*?)\/(trunk|branches|tags).*?<\/url>/);
198198

199-
const result = await this.svn.list(branchUrl);
200-
201-
if (result.exitCode !== 0) {
202-
throw new Error(result.stderr);
199+
if (match[1]) {
200+
repoUrl = match[1];
203201
}
204202

205-
const branches = result.stdout
206-
.trim()
207-
.replace(/\/|\\/g, "")
208-
.split("\n");
209-
210-
return ["trunk", ...branches];
203+
return repoUrl;
211204
}
212205

213-
async branch(name: string) {
214-
const info = await this.svn.info(this.root);
206+
async getBranches() {
207+
const repoUrl = await this.getRepoUrl();
215208

216-
if (info.exitCode !== 0) {
217-
throw new Error(info.stderr);
209+
const branches = [];
210+
211+
let trunkExists = await this.svn.exec("", ["ls", repoUrl + "/trunk", "--depth", "empty"]);
212+
213+
if (trunkExists.exitCode === 0) {
214+
branches.push("trunk");
218215
}
219216

220-
const repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
217+
const trees = ["branches", "tags"];
218+
219+
for (let index in trees) {
220+
const tree = trees[index];
221+
const branchUrl = repoUrl + "/" + tree;
222+
223+
const result = await this.svn.list(branchUrl);
224+
225+
if (result.exitCode !== 0) {
226+
continue;
227+
}
228+
229+
const list = result.stdout
230+
.trim()
231+
.replace(/\/|\\/g, "")
232+
.split(/[\r\n]+/)
233+
.map((i: string) => tree + "/" + i);
234+
235+
branches.push(...list);
236+
237+
}
238+
239+
240+
return branches;
241+
}
242+
243+
async branch(name: string) {
244+
const repoUrl = await this.getRepoUrl();
221245
const newBranch = repoUrl + "/branches/" + name;
222246
const rootUrl = repoUrl + "/trunk";
223247

@@ -237,19 +261,9 @@ export class Repository {
237261
}
238262

239263
async switchBranch(ref: string) {
240-
const info = await this.svn.info(this.root);
241-
242-
if (info.exitCode !== 0) {
243-
throw new Error(info.stderr);
244-
}
245-
246-
const repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
247-
248-
if (ref === "trunk") {
249-
var branchUrl = repoUrl + "/trunk";
250-
} else {
251-
var branchUrl = repoUrl + "/branches/" + ref;
252-
}
264+
const repoUrl = await this.getRepoUrl();
265+
266+
var branchUrl = repoUrl + "/" + ref;
253267

254268
const switchBranch = await this.svn.switchBranch(this.root, branchUrl);
255269

0 commit comments

Comments
 (0)