@@ -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,9 +146,8 @@ export class Model {
119146 }
120147 }
121148
122- async tryOpenRepository ( path : string , level = 1 ) : Promise < void > {
123- // @todo add a config value and run a recursive function to scan folders for the defined depth
124- if ( this . getRepository ( path ) || level > 4 ) {
149+ async tryOpenRepository ( path : string , level = 0 ) : Promise < void > {
150+ if ( this . getRepository ( path ) ) {
125151 return ;
126152 }
127153
@@ -137,12 +163,15 @@ export class Model {
137163 this . open ( repository ) ;
138164 } catch ( err ) {
139165 const newLevel = level + 1 ;
140- fs . readdirSync ( path ) . forEach ( file => {
141- const dir = path + "/" + file ;
142- if ( fs . statSync ( dir ) . isDirectory ( ) ) {
143- this . tryOpenRepository ( dir , newLevel ) ;
144- }
145- } ) ;
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+ }
146175
147176 return ;
148177 }
0 commit comments