@@ -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 ( / < 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+
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 ( / < u r l > ( .* ?) < \/ u r l > / ) [ 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