Skip to content

Commit 7d1d56c

Browse files
authored
Merge pull request #55 from edgardmessias/non_standard_54
Added support to configure non-standard layout (Close #54)
2 parents 5ecfafc + 8c97511 commit 7d1d56c

File tree

5 files changed

+95
-31
lines changed

5 files changed

+95
-31
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# **v1.4.0 under development**
2+
3+
## What's New
4+
5+
* @edgardmessias Added support to configure non-standard layout. To configure, edit the options:
6+
* "svn.layout.trunk" : Relative path for 'trunk' in SVN URL, 'null' to disable. (Ex.: 'trunk', 'main')
7+
* "svn.layout.branches" : Relative path for 'branches' in SVN URL, 'null' to disable. (Ex.: 'branches', 'versions')
8+
* "svn.layout.tags" : Relative path for 'tags' in SVN URL, 'null' to disable. (Ex.: 'tags', 'stamps')
9+
10+
## Bug Fixes
11+
12+
* @edgardmessias Fixed config option form svn path
13+
114
# **v1.3.2**
215

316
## Bug Fixes

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ Files\TortoiseSVN\bin` is available in PATH.
3030
[Issues](https://github.com/JohnstonCode/svn-scm/issues)
3131
* Feel free to submit
3232
[pull requests](https://github.com/JohnstonCode/svn-scm/pulls)
33+
34+
## Contributors
35+
36+
* @JohnstonCode
37+
* @edgardmessias

package.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,28 @@
124124
"type": "boolean",
125125
"description": "Whether svn is enabled",
126126
"default": true
127+
},
128+
"svn.path": {
129+
"type": ["string", "null"],
130+
"description": "Path to the svn executable",
131+
"default": null,
132+
"isExecutable": true
133+
},
134+
"svn.layout.trunk": {
135+
"type": ["string", "null"],
136+
"description": "Relative path for 'trunk' in SVN URL, 'null' to disable. (Ex.: 'trunk', 'main')",
137+
"default": "trunk"
138+
},
139+
"svn.layout.branches": {
140+
"type": ["string", "null"],
141+
"description": "Relative path for 'branches' in SVN URL, 'null' to disable. (Ex.: 'branches', 'versions')",
142+
"default": "branches"
143+
},
144+
"svn.layout.tags": {
145+
"type": ["string", "null"],
146+
"description": "Relative path for 'tags' in SVN URL, 'null' to disable. (Ex.: 'tags', 'stamps')",
147+
"default": "tags"
127148
}
128-
},
129-
"svn.path": {
130-
"type": ["string", "null"],
131-
"description": "Path to the svn executable",
132-
"default": null,
133-
"isExecutable": true
134149
}
135150
}
136151
}

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SwitchBranchItem implements QuickPickItem {
6363
this.tree = parts[0];
6464
this.name = parts[1];
6565
} else {
66-
this.tree = "trunk";
66+
this.tree = parts[0];
6767
this.name = parts[0];
6868
}
6969
}

src/svnRepository.ts

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { workspace } from "vscode";
12
import { Svn, CpOptions } from "./svn";
23

34
export class Repository {
@@ -62,16 +63,22 @@ export class Repository {
6263
}
6364

6465
async getRepoUrl() {
66+
const config = workspace.getConfiguration("svn");
67+
const trunkLayout = config.get<string>("layout.trunk");
68+
const branchesLayout = config.get<string>("layout.branches");
69+
const tagsLayout = config.get<string>("layout.tags");
70+
71+
const trees = [trunkLayout, branchesLayout, tagsLayout].filter(x => x != null);
72+
const regex = new RegExp("<url>(.*?)\/(" + trees.join("|") + ").*?<\/url>");
73+
6574
const info = await this.svn.info(this.root);
6675

6776
if (info.exitCode !== 0) {
6877
throw new Error(info.stderr);
6978
}
7079

7180
let repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
72-
const match = info.stdout.match(
73-
/<url>(.*?)\/(trunk|branches|tags).*?<\/url>/
74-
);
81+
const match = info.stdout.match(regex);
7582

7683
if (match && match[1]) {
7784
repoUrl = match[1];
@@ -81,30 +88,45 @@ export class Repository {
8188
}
8289

8390
async getBranches() {
91+
const config = workspace.getConfiguration("svn");
92+
const trunkLayout = config.get<string>("layout.trunk");
93+
const branchesLayout = config.get<string>("layout.branches");
94+
const tagsLayout = config.get<string>("layout.tags");
95+
8496
const repoUrl = await this.getRepoUrl();
8597

8698
let branches: string[] = [];
8799

88100
let promises = [];
89101

90-
promises.push(
91-
new Promise<string[]>(async resolve => {
92-
let trunkExists = await this.svn.exec("", [
93-
"ls",
94-
repoUrl + "/trunk",
95-
"--depth",
96-
"empty"
97-
]);
98-
99-
if (trunkExists.exitCode === 0) {
100-
resolve(["trunk"]);
101-
return;
102-
}
103-
resolve([]);
104-
})
105-
);
106-
107-
const trees = ["branches", "tags"];
102+
if (trunkLayout) {
103+
promises.push(
104+
new Promise<string[]>(async resolve => {
105+
let trunkExists = await this.svn.exec("", [
106+
"ls",
107+
repoUrl + "/" + trunkLayout,
108+
"--depth",
109+
"empty"
110+
]);
111+
112+
if (trunkExists.exitCode === 0) {
113+
resolve([trunkLayout]);
114+
return;
115+
}
116+
resolve([]);
117+
})
118+
);
119+
}
120+
121+
let trees: string[] = [];
122+
123+
if (branchesLayout) {
124+
trees.push(branchesLayout);
125+
}
126+
127+
if (tagsLayout) {
128+
trees.push(tagsLayout);
129+
}
108130

109131
for (let index in trees) {
110132
promises.push(
@@ -139,11 +161,20 @@ export class Repository {
139161
}
140162

141163
async branch(name: string) {
164+
const config = workspace.getConfiguration("svn");
165+
const branchesLayout = config.get<string>("layout.branches");
166+
167+
if (!branchesLayout) {
168+
return false;
169+
}
170+
142171
const repoUrl = await this.getRepoUrl();
143-
const newBranch = repoUrl + "/branches/" + name;
144-
const rootUrl = repoUrl + "/trunk";
172+
const newBranch = repoUrl + "/" + branchesLayout + "/" + name;
173+
const resultBranch = await this.svn.info(this.root);
174+
const currentBranch = resultBranch.stdout
175+
.match(/<url>(.*?)<\/url>/)[1];
145176

146-
const result = await this.svn.copy(rootUrl, newBranch, name);
177+
const result = await this.svn.copy(currentBranch, newBranch, name);
147178

148179
if (result.exitCode !== 0) {
149180
throw new Error(result.stderr);

0 commit comments

Comments
 (0)