Skip to content

Commit 6cbe942

Browse files
committed
Removed svn-spawn
1 parent e406fbc commit 6cbe942

File tree

3 files changed

+43
-59
lines changed

3 files changed

+43
-59
lines changed

src/commands.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ SvnCommands.prototype.fileOpen = resourceUri => {
6868
};
6969

7070
SvnCommands.prototype.commitWithMessage = async function(repository) {
71-
const svn = new Svn(repository.root);
7271
let message = repository.inputBox.value;
7372

7473
try {
75-
await svn.commit(message);
74+
await repository.commit(message);
7675
repository.inputBox.value = "";
7776
changesCommitted();
7877
} catch (error) {
79-
console.log(error);
78+
window.showErrorMessage("Unable to commit");
8079
}
8180
};
8281

@@ -86,7 +85,7 @@ SvnCommands.prototype.addFile = async uri => {
8685
try {
8786
await this.svn.add(uri.resourceUri.fsPath);
8887
} catch (error) {
89-
console.log(error);
88+
window.showErrorMessage("Unable to add file");
9089
}
9190
};
9291

src/svn.js

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
const SvnSpawn = require("svn-spawn");
21
const vscode = require("vscode");
32
const cp = require("child_process");
43
const iconv = require("iconv-lite");
54

6-
function svn(cwd = null) {
7-
this.client = new SvnSpawn({
8-
noAuthCache: true,
9-
cwd: cwd
10-
});
11-
this.canRun = true;
12-
5+
function svn() {
136
this.isSVNAvailable().catch(() => {
14-
this.canRun = false;
157
vscode.window.showErrorMessage(
168
"SVN is not available in your PATH. svn-scm is unable to run!"
179
);
@@ -20,22 +12,33 @@ function svn(cwd = null) {
2012

2113
svn.prototype.exec = function(cwd, args, options = {}) {
2214
return new Promise((resolve, reject) => {
23-
options.cwd = cwd;
15+
if (cwd) {
16+
options.cwd = cwd;
17+
}
2418
const result = cp.spawn("svn", args, options);
25-
let buffers = [];
19+
let outBuffers = [];
20+
let errBuffers = [];
2621

2722
result.stdout.on("data", b => {
28-
buffers.push(b);
23+
outBuffers.push(b);
2924
});
30-
result.stderr.on("data", data => {
31-
reject();
25+
result.stderr.on("data", b => {
26+
errBuffers.push(b);
3227
});
3328
result.on("error", data => {
3429
reject();
3530
});
3631
result.on("close", () => {
37-
resolve(
38-
Buffer.concat(buffers)
32+
if (outBuffers.length > 0) {
33+
resolve(
34+
Buffer.concat(outBuffers)
35+
.toString()
36+
.trim()
37+
);
38+
}
39+
40+
reject(
41+
Buffer.concat(errBuffers)
3942
.toString()
4043
.trim()
4144
);
@@ -45,10 +48,10 @@ svn.prototype.exec = function(cwd, args, options = {}) {
4548

4649
svn.prototype.getRepositoryRoot = async function(path) {
4750
try {
48-
let result = await this.cmd(["info", path, "--show-item", "wc-root"]);
51+
let result = await this.exec(path, ["info", "--show-item", "wc-root"]);
4952
return result;
5053
} catch (error) {
51-
throw new Error("Not a SVN repo");
54+
throw new Error("not a SVN repo");
5255
}
5356
};
5457

@@ -68,34 +71,17 @@ svn.prototype.open = function(repositoryRoot, workspaceRoot) {
6871
return new Repository(this, repositoryRoot, workspaceRoot);
6972
};
7073

71-
svn.prototype.cmd = function(args) {
72-
return new Promise((resolve, reject) => {
73-
this.client.cmd(args, (err, data) => (err ? reject(err) : resolve(data)));
74-
});
74+
svn.prototype.add = function(filePath) {
75+
filePath = filePath.replace(/\\/g, "/");
76+
return this.exec("", ["add", filePath]);
7577
};
7678

77-
svn.prototype.getStatus = function() {
78-
return new Promise((resolve, reject) => {
79-
this.client.getStatus((err, data) => (err ? reject(err) : resolve(data)));
80-
});
79+
svn.prototype.show = async function(filePath) {
80+
return this.exec("", ["cat", "-r", "HEAD", filePath]);
8181
};
8282

83-
svn.prototype.commit = function(params) {
84-
return new Promise((resolve, reject) => {
85-
this.client.commit(
86-
params,
87-
(err, data) => (err ? reject(err) : resolve(data))
88-
);
89-
});
90-
};
91-
92-
svn.prototype.add = function(filePath) {
93-
return new Promise((resolve, reject) => {
94-
this.client.add(
95-
filePath,
96-
(err, data) => (err ? reject(err) : resolve(data))
97-
);
98-
});
83+
svn.prototype.list = async function(filePath) {
84+
return this.exec("", ["ls", filePath]);
9985
};
10086

10187
module.exports = svn;
@@ -104,11 +90,6 @@ function Repository(svn, repositoryRoot, workspaceRoot) {
10490
this.svn = svn;
10591
this.root = repositoryRoot;
10692
this.workspaceRoot = workspaceRoot;
107-
108-
this.svn.client.option({
109-
cwd: this.workspaceRoot,
110-
noAuthCache: true
111-
});
11293
}
11394

11495
Repository.prototype.getStatus = function() {
@@ -135,3 +116,12 @@ Repository.prototype.getStatus = function() {
135116
});
136117
});
137118
};
119+
120+
Repository.prototype.commit = async function(message) {
121+
try {
122+
let result = await this.svn.exec(this.root, ["commit", "-m", message]);
123+
return result;
124+
} catch (error) {
125+
throw new Error("unable to commit files");
126+
}
127+
};

src/svnContentProvider.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ function SvnContentProvider() {
1010
SvnContentProvider.prototype.provideTextDocumentContent = function(uri) {
1111
return new Promise((resolve, reject) => {
1212
this.svn
13-
.cmd(["ls", uri.fsPath])
14-
.then(() => this.svn.cmd(["cat", "-r", "HEAD", uri.fsPath]))
15-
.then(result => {
16-
resolve(result);
17-
})
18-
.catch(err => {
19-
// reject(err);
20-
});
13+
.show(uri.fsPath)
14+
.then(result => resolve(result))
15+
.catch(error => reject(error));
2116
});
2217
};
2318

0 commit comments

Comments
 (0)