@@ -3,7 +3,7 @@ import { window } from "vscode";
3
3
import * as cp from "child_process" ;
4
4
import * as iconv from "iconv-lite" ;
5
5
import * as jschardet from "jschardet" ;
6
- import * as path from ' path' ;
6
+ import * as path from " path" ;
7
7
8
8
interface CpOptions {
9
9
cwd ?: string ;
@@ -19,7 +19,7 @@ export interface ISvn {
19
19
function parseVersion ( raw : string ) : string {
20
20
const match = raw . match ( / ( \d + \. \d + \. \d + \( r \d + \) ) / ) ;
21
21
22
- if ( match && match [ 0 ] ) {
22
+ if ( match && match [ 0 ] ) {
23
23
return match [ 0 ] ;
24
24
}
25
25
return raw . split ( / [ \r \n ] + / ) [ 0 ] ;
@@ -28,44 +28,57 @@ function parseVersion(raw: string): string {
28
28
function findSpecificSvn ( path : string ) : Promise < ISvn > {
29
29
return new Promise < ISvn > ( ( c , e ) => {
30
30
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
+ ) ;
35
48
} ) ;
36
49
}
37
50
38
51
function findSvnDarwin ( ) : Promise < ISvn > {
39
52
return new Promise < ISvn > ( ( c , e ) => {
40
- cp . exec ( ' which svn' , ( err , svnPathBuffer ) => {
53
+ cp . exec ( " which svn" , ( err , svnPathBuffer ) => {
41
54
if ( err ) {
42
- return e ( ' svn not found' ) ;
55
+ return e ( " svn not found" ) ;
43
56
}
44
57
45
- const path = svnPathBuffer . toString ( ) . replace ( / ^ \s + | \s + $ / g, '' ) ;
58
+ const path = svnPathBuffer . toString ( ) . replace ( / ^ \s + | \s + $ / g, "" ) ;
46
59
47
60
function getVersion ( path : string ) {
48
61
// make sure svn executes
49
- cp . exec ( ' svn --version' , ( err , stdout ) => {
62
+ cp . exec ( " svn --version" , ( err , stdout ) => {
50
63
if ( err ) {
51
- return e ( ' svn not found' ) ;
64
+ return e ( " svn not found" ) ;
52
65
}
53
66
54
67
return c ( { path, version : parseVersion ( stdout . trim ( ) ) } ) ;
55
68
} ) ;
56
69
}
57
70
58
- if ( path !== ' /usr/bin/svn' ) {
71
+ if ( path !== " /usr/bin/svn" ) {
59
72
return getVersion ( path ) ;
60
73
}
61
74
62
75
// must check if XCode is installed
63
- cp . exec ( ' xcode-select -p' , ( err : any ) => {
76
+ cp . exec ( " xcode-select -p" , ( err : any ) => {
64
77
if ( err && err . code === 2 ) {
65
78
// svn is not installed, and launching /usr/bin/svn
66
79
// will prompt the user to install it
67
80
68
- return e ( ' svn not found' ) ;
81
+ return e ( " svn not found" ) ;
69
82
}
70
83
71
84
getVersion ( path ) ;
@@ -76,17 +89,17 @@ function findSvnDarwin(): Promise<ISvn> {
76
89
77
90
function findSystemSvnWin32 ( base : string ) : Promise < ISvn > {
78
91
if ( ! base ) {
79
- return Promise . reject < ISvn > ( ' Not found' ) ;
92
+ return Promise . reject < ISvn > ( " Not found" ) ;
80
93
}
81
94
82
- return findSpecificSvn ( path . join ( base , ' TortoiseSVN' , ' bin' , ' svn.exe' ) ) ;
95
+ return findSpecificSvn ( path . join ( base , " TortoiseSVN" , " bin" , " svn.exe" ) ) ;
83
96
}
84
97
85
98
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" ) ) ;
90
103
}
91
104
92
105
export function findSvn ( hint : string | undefined ) : Promise < ISvn > {
@@ -95,21 +108,24 @@ export function findSvn(hint: string | undefined): Promise<ISvn> {
95
108
return first
96
109
. then ( void 0 , ( ) => {
97
110
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" ) ;
101
117
}
102
118
} )
103
- . then ( null , ( ) => Promise . reject ( new Error ( ' Svn installation not found.' ) ) ) ;
119
+ . then ( null , ( ) => Promise . reject ( new Error ( " Svn installation not found." ) ) ) ;
104
120
}
105
121
106
122
function cpErrorHandler ( cb : ( reason ?: any ) => void ) : ( reason ?: any ) => void {
107
123
return err => {
108
124
if ( / E N O E N T / . test ( err . message ) ) {
109
125
err = new SvnError ( {
110
126
error : err ,
111
- message : ' Failed to execute svn (ENOENT)' ,
112
- svnErrorCode : ' NotASvnRepository'
127
+ message : " Failed to execute svn (ENOENT)" ,
128
+ svnErrorCode : " NotASvnRepository"
113
129
} ) ;
114
130
}
115
131
@@ -128,7 +144,6 @@ export interface ISvnErrorData {
128
144
}
129
145
130
146
export class SvnError {
131
-
132
147
error ?: Error ;
133
148
message : string ;
134
149
stdout ?: string ;
@@ -145,7 +160,7 @@ export class SvnError {
145
160
this . error = void 0 ;
146
161
}
147
162
148
- this . message = this . message || data . message || ' SVN error' ;
163
+ this . message = this . message || data . message || " SVN error" ;
149
164
this . stdout = data . stdout ;
150
165
this . stderr = data . stderr ;
151
166
this . exitCode = data . exitCode ;
@@ -154,13 +169,20 @@ export class SvnError {
154
169
}
155
170
156
171
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
+ ) ;
164
186
165
187
if ( this . error ) {
166
188
result += ( < any > this . error ) . stack ;
@@ -249,20 +271,6 @@ export class Svn {
249
271
}
250
272
}
251
273
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
-
266
274
open ( repositoryRoot : string , workspaceRoot : string ) : Repository {
267
275
return new Repository ( this , repositoryRoot , workspaceRoot ) ;
268
276
}
0 commit comments