@@ -20,6 +20,8 @@ export class Model {
2020 private disposables : Disposable [ ] = [ ] ;
2121 private enabled = false ;
2222 private possibleSvnRepositoryPaths = new Set < string > ( ) ;
23+ private ignorePattern : RegExp = / ^ $ / ;
24+ private maxDepth : number = 0 ;
2325
2426 get repositories ( ) : Repository [ ] {
2527 return this . openRepositories . map ( r => r . repository ) ;
@@ -31,6 +33,31 @@ export class Model {
3133
3234 if ( this . enabled ) {
3335 this . init ( ) ;
36+
37+ const multipleFolders = config . get < boolean > (
38+ "multipleFolders.enabled" ,
39+ false
40+ ) ;
41+
42+ if ( multipleFolders ) {
43+ this . maxDepth = config . get < number > ( "multipleFolders.depth" , 0 ) ;
44+
45+ const ignoreList = config . get ( "multipleFolders.ignore" , [ ] ) ;
46+
47+ // Base on https://github.com/aleclarson/glob-regex/blob/master/index.js
48+ const pattern = ignoreList
49+ . join ( "|" )
50+ . replace ( / \. / g, "\\." )
51+ . replace ( / \* \* \/ / g, "(.+[\\\\\/])?" )
52+ . replace ( / \* \* / g, "(.+[\\\\\/])?*" )
53+ . replace ( / \* / g, "[^\\\\\/]+" ) ;
54+
55+ try {
56+ this . ignorePattern = new RegExp ( "^(" + pattern + ")$" ) ;
57+ } catch ( error ) {
58+ window . showErrorMessage ( "Invalid pattern for: " + pattern ) ;
59+ }
60+ }
3461 } else {
3562 this . disable ( ) ;
3663 }
@@ -119,7 +146,7 @@ export class Model {
119146 }
120147 }
121148
122- async tryOpenRepository ( path : string ) : Promise < void > {
149+ async tryOpenRepository ( path : string , level = 0 ) : Promise < void > {
123150 if ( this . getRepository ( path ) ) {
124151 return ;
125152 }
@@ -135,7 +162,17 @@ export class Model {
135162
136163 this . open ( repository ) ;
137164 } catch ( err ) {
138- console . error ( err ) ;
165+ const newLevel = level + 1 ;
166+
167+ if ( newLevel <= this . maxDepth ) {
168+ fs . readdirSync ( path ) . forEach ( file => {
169+ const dir = path + "/" + file ;
170+ if ( fs . statSync ( dir ) . isDirectory ( ) && ! this . ignorePattern . test ( dir ) ) {
171+ this . tryOpenRepository ( dir , newLevel ) ;
172+ }
173+ } ) ;
174+ }
175+
139176 return ;
140177 }
141178 }
0 commit comments