@@ -186,38 +186,62 @@ export class Repository {
186186 }
187187 }
188188
189- async getBranches ( ) {
189+ async getRepoUrl ( ) {
190190 const info = await this . svn . info ( this . root ) ;
191-
191+
192192 if ( info . exitCode !== 0 ) {
193193 throw new Error ( info . stderr ) ;
194194 }
195195
196- const repoUrl = info . stdout . match ( / < r o o t > ( .* ?) < \/ r o o t > / ) [ 1 ] ;
197- const branchUrl = repoUrl + "/ branches" ;
196+ let repoUrl = info . stdout . match ( / < r o o t > ( .* ?) < \/ r o o t > / ) [ 1 ] ;
197+ const match = info . stdout . match ( / < u r l > ( . * ? ) \/ ( t r u n k | b r a n c h e s | t a g s ) . * ? < \/ u r l > / ) ;
198198
199- const result = await this . svn . list ( branchUrl ) ;
200-
201- if ( result . exitCode !== 0 ) {
202- throw new Error ( result . stderr ) ;
199+ if ( match [ 1 ] ) {
200+ repoUrl = match [ 1 ] ;
203201 }
204202
205- const branches = result . stdout
206- . trim ( )
207- . replace ( / \/ | \\ / g, "" )
208- . split ( "\n" ) ;
209-
210- return [ "trunk" , ...branches ] ;
203+ return repoUrl ;
211204 }
212205
213- async branch ( name : string ) {
214- const info = await this . svn . info ( this . root ) ;
206+ async getBranches ( ) {
207+ const repoUrl = await this . getRepoUrl ( ) ;
215208
216- if ( info . exitCode !== 0 ) {
217- throw new Error ( info . stderr ) ;
209+ const branches = [ ] ;
210+
211+ let trunkExists = await this . svn . exec ( "" , [ "ls" , repoUrl + "/trunk" , "--depth" , "empty" ] ) ;
212+
213+ if ( trunkExists . exitCode === 0 ) {
214+ branches . push ( "trunk" ) ;
218215 }
219216
220- const repoUrl = info . stdout . match ( / < r o o t > ( .* ?) < \/ r o o t > / ) [ 1 ] ;
217+ const trees = [ "branches" , "tags" ] ;
218+
219+ for ( let index in trees ) {
220+ const tree = trees [ index ] ;
221+ const branchUrl = repoUrl + "/" + tree ;
222+
223+ const result = await this . svn . list ( branchUrl ) ;
224+
225+ if ( result . exitCode !== 0 ) {
226+ continue ;
227+ }
228+
229+ const list = result . stdout
230+ . trim ( )
231+ . replace ( / \/ | \\ / g, "" )
232+ . split ( / [ \r \n ] + / )
233+ . map ( ( i : string ) => tree + "/" + i ) ;
234+
235+ branches . push ( ...list ) ;
236+
237+ }
238+
239+
240+ return branches ;
241+ }
242+
243+ async branch ( name : string ) {
244+ const repoUrl = await this . getRepoUrl ( ) ;
221245 const newBranch = repoUrl + "/branches/" + name ;
222246 const rootUrl = repoUrl + "/trunk" ;
223247
@@ -237,19 +261,9 @@ export class Repository {
237261 }
238262
239263 async switchBranch ( ref : string ) {
240- const info = await this . svn . info ( this . root ) ;
241-
242- if ( info . exitCode !== 0 ) {
243- throw new Error ( info . stderr ) ;
244- }
245-
246- const repoUrl = info . stdout . match ( / < r o o t > ( .* ?) < \/ r o o t > / ) [ 1 ] ;
247-
248- if ( ref === "trunk" ) {
249- var branchUrl = repoUrl + "/trunk" ;
250- } else {
251- var branchUrl = repoUrl + "/branches/" + ref ;
252- }
264+ const repoUrl = await this . getRepoUrl ( ) ;
265+
266+ var branchUrl = repoUrl + "/" + ref ;
253267
254268 const switchBranch = await this . svn . switchBranch ( this . root , branchUrl ) ;
255269
0 commit comments