1+ import { workspace } from "vscode" ;
12import { Svn , CpOptions } from "./svn" ;
23
34export class Repository {
@@ -62,16 +63,22 @@ export class Repository {
6263 }
6364
6465 async getRepoUrl ( ) {
66+ const config = workspace . getConfiguration ( "svn" ) ;
67+ const trunkLayout = config . get < string > ( "layout.trunk" ) ;
68+ const branchesLayout = config . get < string > ( "layout.branches" ) ;
69+ const tagsLayout = config . get < string > ( "layout.tags" ) ;
70+
71+ const trees = [ trunkLayout , branchesLayout , tagsLayout ] . filter ( x => x != null ) ;
72+ const regex = new RegExp ( "<url>(.*?)\/(" + trees . join ( "|" ) + ").*?<\/url>" ) ;
73+
6574 const info = await this . svn . info ( this . root ) ;
6675
6776 if ( info . exitCode !== 0 ) {
6877 throw new Error ( info . stderr ) ;
6978 }
7079
7180 let repoUrl = info . stdout . match ( / < r o o t > ( .* ?) < \/ r o o t > / ) [ 1 ] ;
72- const match = info . stdout . match (
73- / < u r l > ( .* ?) \/ ( t r u n k | b r a n c h e s | t a g s ) .* ?< \/ u r l > /
74- ) ;
81+ const match = info . stdout . match ( regex ) ;
7582
7683 if ( match && match [ 1 ] ) {
7784 repoUrl = match [ 1 ] ;
@@ -81,30 +88,45 @@ export class Repository {
8188 }
8289
8390 async getBranches ( ) {
91+ const config = workspace . getConfiguration ( "svn" ) ;
92+ const trunkLayout = config . get < string > ( "layout.trunk" ) ;
93+ const branchesLayout = config . get < string > ( "layout.branches" ) ;
94+ const tagsLayout = config . get < string > ( "layout.tags" ) ;
95+
8496 const repoUrl = await this . getRepoUrl ( ) ;
8597
8698 let branches : string [ ] = [ ] ;
8799
88100 let promises = [ ] ;
89101
90- promises . push (
91- new Promise < string [ ] > ( async resolve => {
92- let trunkExists = await this . svn . exec ( "" , [
93- "ls" ,
94- repoUrl + "/trunk" ,
95- "--depth" ,
96- "empty"
97- ] ) ;
98-
99- if ( trunkExists . exitCode === 0 ) {
100- resolve ( [ "trunk" ] ) ;
101- return ;
102- }
103- resolve ( [ ] ) ;
104- } )
105- ) ;
106-
107- const trees = [ "branches" , "tags" ] ;
102+ if ( trunkLayout ) {
103+ promises . push (
104+ new Promise < string [ ] > ( async resolve => {
105+ let trunkExists = await this . svn . exec ( "" , [
106+ "ls" ,
107+ repoUrl + "/" + trunkLayout ,
108+ "--depth" ,
109+ "empty"
110+ ] ) ;
111+
112+ if ( trunkExists . exitCode === 0 ) {
113+ resolve ( [ trunkLayout ] ) ;
114+ return ;
115+ }
116+ resolve ( [ ] ) ;
117+ } )
118+ ) ;
119+ }
120+
121+ let trees : string [ ] = [ ] ;
122+
123+ if ( branchesLayout ) {
124+ trees . push ( branchesLayout ) ;
125+ }
126+
127+ if ( tagsLayout ) {
128+ trees . push ( tagsLayout ) ;
129+ }
108130
109131 for ( let index in trees ) {
110132 promises . push (
@@ -139,11 +161,20 @@ export class Repository {
139161 }
140162
141163 async branch ( name : string ) {
164+ const config = workspace . getConfiguration ( "svn" ) ;
165+ const branchesLayout = config . get < string > ( "layout.branches" ) ;
166+
167+ if ( ! branchesLayout ) {
168+ return false ;
169+ }
170+
142171 const repoUrl = await this . getRepoUrl ( ) ;
143- const newBranch = repoUrl + "/branches/" + name ;
144- const rootUrl = repoUrl + "/trunk" ;
172+ const newBranch = repoUrl + "/" + branchesLayout + "/" + name ;
173+ const resultBranch = await this . svn . info ( this . root ) ;
174+ const currentBranch = resultBranch . stdout
175+ . match ( / < u r l > ( .* ?) < \/ u r l > / ) [ 1 ] ;
145176
146- const result = await this . svn . copy ( rootUrl , newBranch , name ) ;
177+ const result = await this . svn . copy ( currentBranch , newBranch , name ) ;
147178
148179 if ( result . exitCode !== 0 ) {
149180 throw new Error ( result . stderr ) ;
0 commit comments