Skip to content

Commit 3ff3b95

Browse files
authored
Merge pull request #107 from edgardmessias/fix_multi_workspace
Fixed multi-project workspace (Close #83)
2 parents 6519e9f + 6b4844e commit 3ff3b95

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

src/model.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as path from "path";
1010
import { Repository } from "./repository";
1111
import { Svn } from "./svn";
1212
import { dispose, anyEvent, filterEvent } from "./util";
13+
import { sequentialize } from "./decorators";
1314

1415
interface OpenRepository {
1516
repository: Repository;
@@ -47,6 +48,8 @@ export class Model {
4748
const config = workspace.getConfiguration("svn");
4849
const enabled = config.get("enabled") === true;
4950

51+
this.maxDepth = config.get<number>("multipleFolders.depth", 0);
52+
5053
if (enabled === this.enabled) {
5154
return;
5255
}
@@ -148,7 +151,7 @@ export class Model {
148151
this.disposables = dispose(this.disposables);
149152
}
150153

151-
private onDidChangeWorkspaceFolders({
154+
private async onDidChangeWorkspaceFolders({
152155
added,
153156
removed
154157
}: WorkspaceFoldersChangeEvent) {
@@ -162,7 +165,7 @@ export class Model {
162165
.filter(
163166
repository =>
164167
!(workspace.workspaceFolders || []).some(f =>
165-
repository!.repository.root.startsWith(f.uri.fsPath)
168+
repository!.repository.workspaceRoot.startsWith(f.uri.fsPath)
166169
)
167170
) as OpenRepository[];
168171

@@ -179,6 +182,7 @@ export class Model {
179182
}
180183
}
181184

185+
@sequentialize
182186
async tryOpenRepository(path: string, level = 0): Promise<void> {
183187
if (this.getRepository(path)) {
184188
return;
@@ -203,10 +207,6 @@ export class Model {
203207
try {
204208
const repositoryRoot = await this.svn.getRepositoryRoot(path);
205209

206-
if (this.getRepository(repositoryRoot)) {
207-
return;
208-
}
209-
210210
const repository = new Repository(this.svn.open(repositoryRoot, path));
211211

212212
this.open(repository);
@@ -248,7 +248,7 @@ export class Model {
248248
if (hint instanceof Uri) {
249249
for (const liveRepository of this.openRepositories) {
250250
const relativePath = path.relative(
251-
liveRepository.repository.root,
251+
liveRepository.repository.workspaceRoot,
252252
hint.fsPath
253253
);
254254

src/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Repository {
8080
this.sourceControl = scm.createSourceControl(
8181
"svn",
8282
"SVN",
83-
Uri.file(repository.root)
83+
Uri.file(repository.workspaceRoot)
8484
);
8585
this.sourceControl.acceptInputCommand = {
8686
command: "svn.commitWithMessage",

src/svnRepository.ts

Lines changed: 37 additions & 18 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.root);
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");
@@ -79,7 +98,7 @@ export class Repository {
7998
);
8099
const regex = new RegExp("<url>(.*?)/(" + trees.join("|") + ").*?</url>");
81100

82-
const info = await this.svn.info(this.root);
101+
const info = await this.svn.info(this.workspaceRoot);
83102

84103
if (info.exitCode !== 0) {
85104
throw new Error(info.stderr);
@@ -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);
@@ -178,15 +197,15 @@ export class Repository {
178197

179198
const repoUrl = await this.getRepoUrl();
180199
const newBranch = repoUrl + "/" + branchesLayout + "/" + name;
181-
const resultBranch = await this.svn.info(this.root);
200+
const resultBranch = await this.svn.info(this.workspaceRoot);
182201
const currentBranch = resultBranch.stdout.match(/<url>(.*?)<\/url>/)[1];
183202
const result = await this.svn.copy(currentBranch, newBranch, name);
184203

185204
if (result.exitCode !== 0) {
186205
throw new Error(result.stderr);
187206
}
188207

189-
const switchBranch = await this.svn.switchBranch(this.root, newBranch);
208+
const switchBranch = await this.svn.switchBranch(this.workspaceRoot, newBranch);
190209

191210
if (switchBranch.exitCode !== 0) {
192211
throw new Error(switchBranch.stderr);
@@ -223,7 +242,7 @@ export class Repository {
223242
}
224243

225244
async update() {
226-
const result = await this.svn.update(this.root);
245+
const result = await this.svn.update(this.workspaceRoot);
227246

228247
if (result.exitCode !== 0) {
229248
throw new Error(result.stderr);
@@ -238,7 +257,7 @@ export class Repository {
238257
}
239258

240259
async patch() {
241-
const result = await this.svn.patch(this.root);
260+
const result = await this.svn.patch(this.workspaceRoot);
242261
if (result.exitCode !== 0) {
243262
throw new Error(result.stderr);
244263
}
@@ -249,7 +268,7 @@ export class Repository {
249268

250269
async propset(name:string, flag:string, files:string) {
251270
const filesArray = files.split(" ");
252-
const result = await this.svn.propset(this.root, name, flag, filesArray);
271+
const result = await this.svn.propset(this.workspaceRoot, name, flag, filesArray);
253272

254273
console.log(result);
255274

0 commit comments

Comments
 (0)