@@ -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 . workspaceRoot ) ;
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" ) ;
@@ -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 ) ;
0 commit comments