@@ -55,18 +55,37 @@ export class Repository {
55
55
}
56
56
57
57
async getCurrentBranch ( ) : Promise < string > {
58
- try {
59
- const result = await this . svn . info ( this . root ) ;
60
- const currentBranch = result . stdout
61
- . match ( / < u r l > ( .* ?) < \/ u r l > / ) [ 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
+
67
87
return "" ;
68
88
}
69
- }
70
89
71
90
async getRepoUrl ( ) {
72
91
const config = workspace . getConfiguration ( "svn" ) ;
@@ -79,7 +98,7 @@ export class Repository {
79
98
) ;
80
99
const regex = new RegExp ( "<url>(.*?)/(" + trees . join ( "|" ) + ").*?</url>" ) ;
81
100
82
- const info = await this . svn . info ( this . root ) ;
101
+ const info = await this . svn . info ( this . workspaceRoot ) ;
83
102
84
103
if ( info . exitCode !== 0 ) {
85
104
throw new Error ( info . stderr ) ;
@@ -136,10 +155,9 @@ export class Repository {
136
155
trees . push ( tagsLayout ) ;
137
156
}
138
157
139
- for ( let index in trees ) {
158
+ for ( const tree of trees ) {
140
159
promises . push (
141
160
new Promise < string [ ] > ( async resolve => {
142
- const tree = trees [ index ] ;
143
161
const branchUrl = repoUrl + "/" + tree ;
144
162
145
163
const result = await this . svn . list ( branchUrl ) ;
@@ -153,6 +171,7 @@ export class Repository {
153
171
. trim ( )
154
172
. replace ( / \/ | \\ / g, "" )
155
173
. split ( / [ \r \n ] + / )
174
+ . filter ( ( x : string ) => ! ! x )
156
175
. map ( ( i : string ) => tree + "/" + i ) ;
157
176
158
177
resolve ( list ) ;
@@ -178,15 +197,15 @@ export class Repository {
178
197
179
198
const repoUrl = await this . getRepoUrl ( ) ;
180
199
const newBranch = repoUrl + "/" + branchesLayout + "/" + name ;
181
- const resultBranch = await this . svn . info ( this . root ) ;
200
+ const resultBranch = await this . svn . info ( this . workspaceRoot ) ;
182
201
const currentBranch = resultBranch . stdout . match ( / < u r l > ( .* ?) < \/ u r l > / ) [ 1 ] ;
183
202
const result = await this . svn . copy ( currentBranch , newBranch , name ) ;
184
203
185
204
if ( result . exitCode !== 0 ) {
186
205
throw new Error ( result . stderr ) ;
187
206
}
188
207
189
- const switchBranch = await this . svn . switchBranch ( this . root , newBranch ) ;
208
+ const switchBranch = await this . svn . switchBranch ( this . workspaceRoot , newBranch ) ;
190
209
191
210
if ( switchBranch . exitCode !== 0 ) {
192
211
throw new Error ( switchBranch . stderr ) ;
@@ -223,7 +242,7 @@ export class Repository {
223
242
}
224
243
225
244
async update ( ) {
226
- const result = await this . svn . update ( this . root ) ;
245
+ const result = await this . svn . update ( this . workspaceRoot ) ;
227
246
228
247
if ( result . exitCode !== 0 ) {
229
248
throw new Error ( result . stderr ) ;
@@ -238,7 +257,7 @@ export class Repository {
238
257
}
239
258
240
259
async patch ( ) {
241
- const result = await this . svn . patch ( this . root ) ;
260
+ const result = await this . svn . patch ( this . workspaceRoot ) ;
242
261
if ( result . exitCode !== 0 ) {
243
262
throw new Error ( result . stderr ) ;
244
263
}
@@ -249,7 +268,7 @@ export class Repository {
249
268
250
269
async propset ( name :string , flag :string , files :string ) {
251
270
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 ) ;
253
272
254
273
console . log ( result ) ;
255
274
0 commit comments