Skip to content

Commit a6544b3

Browse files
committed
removed old svn finder check
1 parent e101a68 commit a6544b3

File tree

7 files changed

+76
-97
lines changed

7 files changed

+76
-97
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# **v1.3.0**
2+
3+
## What's New
4+
5+
* @edgardmessias improved the way SVN is detected and added svn path to config
6+
7+
## Bug Fixes
8+
9+
* @edgardmessias fixed #45 failed match
10+
111
# **v1.2.1**
212

313
## Bug Fixes

images/subversion.png

4.84 KB
Loading

images/subversion.svg

Lines changed: 0 additions & 31 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "svn-scm",
33
"displayName": "SVN",
44
"description": "Integrated Subversion source control",
5-
"version": "1.2.1",
5+
"version": "1.3.0",
66
"publisher": "johnstoncode",
77
"engines": {
88
"vscode": "^1.17.0"
99
},
10-
"icon": "images/subversion.svg",
10+
"icon": "images/subversion.png",
1111
"homepage": "https://github.com/JohnstonCode/svn-scm/blob/master/README.md",
1212
"repository": {
1313
"type": "git",
@@ -127,10 +127,7 @@
127127
}
128128
},
129129
"svn.path": {
130-
"type": [
131-
"string",
132-
"null"
133-
],
130+
"type": ["string", "null"],
134131
"description": "Path to the svn executable",
135132
"default": null,
136133
"isExecutable": true

src/model.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ export class Model {
2929
const config = workspace.getConfiguration("svn");
3030
this.enabled = config.get("enabled") === true;
3131

32-
svn
33-
.isSvnAvailable()
34-
.then(() => {
35-
if (this.enabled && svn.isSvnAvailable()) {
36-
this.init();
37-
} else {
38-
this.disable();
39-
}
40-
})
41-
.catch(() => {});
32+
if (this.enabled) {
33+
this.init();
34+
} else {
35+
this.disable();
36+
}
4237
}
4338

4439
private init(): void {

src/svn.ts

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { window } from "vscode";
33
import * as cp from "child_process";
44
import * as iconv from "iconv-lite";
55
import * as jschardet from "jschardet";
6-
import * as path from 'path';
6+
import * as path from "path";
77

88
interface CpOptions {
99
cwd?: string;
@@ -19,7 +19,7 @@ export interface ISvn {
1919
function parseVersion(raw: string): string {
2020
const match = raw.match(/(\d+\.\d+\.\d+ \(r\d+\))/);
2121

22-
if(match && match[0]) {
22+
if (match && match[0]) {
2323
return match[0];
2424
}
2525
return raw.split(/[\r\n]+/)[0];
@@ -28,44 +28,57 @@ function parseVersion(raw: string): string {
2828
function findSpecificSvn(path: string): Promise<ISvn> {
2929
return new Promise<ISvn>((c, e) => {
3030
const buffers: Buffer[] = [];
31-
const child = cp.spawn(path, ['--version']);
32-
child.stdout.on('data', (b: Buffer) => buffers.push(b));
33-
child.on('error', cpErrorHandler(e));
34-
child.on('exit', code => code ? e(new Error('Not found')) : c({ path, version: parseVersion(Buffer.concat(buffers).toString('utf8').trim()) }));
31+
const child = cp.spawn(path, ["--version"]);
32+
child.stdout.on("data", (b: Buffer) => buffers.push(b));
33+
child.on("error", cpErrorHandler(e));
34+
child.on(
35+
"exit",
36+
code =>
37+
code
38+
? e(new Error("Not found"))
39+
: c({
40+
path,
41+
version: parseVersion(
42+
Buffer.concat(buffers)
43+
.toString("utf8")
44+
.trim()
45+
)
46+
})
47+
);
3548
});
3649
}
3750

3851
function findSvnDarwin(): Promise<ISvn> {
3952
return new Promise<ISvn>((c, e) => {
40-
cp.exec('which svn', (err, svnPathBuffer) => {
53+
cp.exec("which svn", (err, svnPathBuffer) => {
4154
if (err) {
42-
return e('svn not found');
55+
return e("svn not found");
4356
}
4457

45-
const path = svnPathBuffer.toString().replace(/^\s+|\s+$/g, '');
58+
const path = svnPathBuffer.toString().replace(/^\s+|\s+$/g, "");
4659

4760
function getVersion(path: string) {
4861
// make sure svn executes
49-
cp.exec('svn --version', (err, stdout) => {
62+
cp.exec("svn --version", (err, stdout) => {
5063
if (err) {
51-
return e('svn not found');
64+
return e("svn not found");
5265
}
5366

5467
return c({ path, version: parseVersion(stdout.trim()) });
5568
});
5669
}
5770

58-
if (path !== '/usr/bin/svn') {
71+
if (path !== "/usr/bin/svn") {
5972
return getVersion(path);
6073
}
6174

6275
// must check if XCode is installed
63-
cp.exec('xcode-select -p', (err: any) => {
76+
cp.exec("xcode-select -p", (err: any) => {
6477
if (err && err.code === 2) {
6578
// svn is not installed, and launching /usr/bin/svn
6679
// will prompt the user to install it
6780

68-
return e('svn not found');
81+
return e("svn not found");
6982
}
7083

7184
getVersion(path);
@@ -76,17 +89,17 @@ function findSvnDarwin(): Promise<ISvn> {
7689

7790
function findSystemSvnWin32(base: string): Promise<ISvn> {
7891
if (!base) {
79-
return Promise.reject<ISvn>('Not found');
92+
return Promise.reject<ISvn>("Not found");
8093
}
8194

82-
return findSpecificSvn(path.join(base, 'TortoiseSVN', 'bin', 'svn.exe'));
95+
return findSpecificSvn(path.join(base, "TortoiseSVN", "bin", "svn.exe"));
8396
}
8497

8598
function findSvnWin32(): Promise<ISvn> {
86-
return findSystemSvnWin32(process.env['ProgramW6432'])
87-
.then(void 0, () => findSystemSvnWin32(process.env['ProgramFiles(x86)']))
88-
.then(void 0, () => findSystemSvnWin32(process.env['ProgramFiles']))
89-
.then(void 0, () => findSpecificSvn('svn'));
99+
return findSystemSvnWin32(process.env["ProgramW6432"])
100+
.then(void 0, () => findSystemSvnWin32(process.env["ProgramFiles(x86)"]))
101+
.then(void 0, () => findSystemSvnWin32(process.env["ProgramFiles"]))
102+
.then(void 0, () => findSpecificSvn("svn"));
90103
}
91104

92105
export function findSvn(hint: string | undefined): Promise<ISvn> {
@@ -95,21 +108,24 @@ export function findSvn(hint: string | undefined): Promise<ISvn> {
95108
return first
96109
.then(void 0, () => {
97110
switch (process.platform) {
98-
case 'darwin': return findSvnDarwin();
99-
case 'win32': return findSvnWin32();
100-
default: return findSpecificSvn('svn');
111+
case "darwin":
112+
return findSvnDarwin();
113+
case "win32":
114+
return findSvnWin32();
115+
default:
116+
return findSpecificSvn("svn");
101117
}
102118
})
103-
.then(null, () => Promise.reject(new Error('Svn installation not found.')));
119+
.then(null, () => Promise.reject(new Error("Svn installation not found.")));
104120
}
105121

106122
function cpErrorHandler(cb: (reason?: any) => void): (reason?: any) => void {
107123
return err => {
108124
if (/ENOENT/.test(err.message)) {
109125
err = new SvnError({
110126
error: err,
111-
message: 'Failed to execute svn (ENOENT)',
112-
svnErrorCode: 'NotASvnRepository'
127+
message: "Failed to execute svn (ENOENT)",
128+
svnErrorCode: "NotASvnRepository"
113129
});
114130
}
115131

@@ -128,7 +144,6 @@ export interface ISvnErrorData {
128144
}
129145

130146
export class SvnError {
131-
132147
error?: Error;
133148
message: string;
134149
stdout?: string;
@@ -145,7 +160,7 @@ export class SvnError {
145160
this.error = void 0;
146161
}
147162

148-
this.message = this.message || data.message || 'SVN error';
163+
this.message = this.message || data.message || "SVN error";
149164
this.stdout = data.stdout;
150165
this.stderr = data.stderr;
151166
this.exitCode = data.exitCode;
@@ -154,13 +169,20 @@ export class SvnError {
154169
}
155170

156171
toString(): string {
157-
let result = this.message + ' ' + JSON.stringify({
158-
exitCode: this.exitCode,
159-
svnErrorCode: this.svnErrorCode,
160-
svnCommand: this.svnCommand,
161-
stdout: this.stdout,
162-
stderr: this.stderr
163-
}, null, 2);
172+
let result =
173+
this.message +
174+
" " +
175+
JSON.stringify(
176+
{
177+
exitCode: this.exitCode,
178+
svnErrorCode: this.svnErrorCode,
179+
svnCommand: this.svnCommand,
180+
stdout: this.stdout,
181+
stderr: this.stderr
182+
},
183+
null,
184+
2
185+
);
164186

165187
if (this.error) {
166188
result += (<any>this.error).stack;
@@ -249,20 +271,6 @@ export class Svn {
249271
}
250272
}
251273

252-
public async isSvnAvailable() {
253-
return new Promise((resolve, reject) => {
254-
cp.exec("svn --version", (error, stdout, stderr) => {
255-
if (error) {
256-
console.log(stderr);
257-
window.showErrorMessage(stderr);
258-
reject();
259-
}
260-
261-
resolve();
262-
});
263-
});
264-
}
265-
266274
open(repositoryRoot: string, workspaceRoot: string): Repository {
267275
return new Repository(this, repositoryRoot, workspaceRoot);
268276
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "commonjs",
66
"outDir": "./out",
77
"typeRoots": ["./node_modules/@types"],
8-
"strict": true,
8+
"strict": false,
99
"experimentalDecorators": true,
1010
"sourceMap": true
1111
},

0 commit comments

Comments
 (0)