@@ -10,6 +10,7 @@ import * as _path from 'path';
1010
1111export enum RepositoryChange {
1212 Config = 'config' ,
13+ Closed = 'closed' ,
1314 // FileSystem = 'file-system',
1415 Remotes = 'remotes' ,
1516 Repository = 'repository' ,
@@ -83,8 +84,9 @@ export class Repository extends Disposable {
8384 public readonly folder : WorkspaceFolder ,
8485 public readonly path : string ,
8586 public readonly root : boolean ,
86- private readonly onAnyRepositoryChanged : ( repo : Repository ) => void ,
87- suspended : boolean
87+ private readonly onAnyRepositoryChanged : ( repo : Repository , reason : RepositoryChange ) => void ,
88+ suspended : boolean ,
89+ closed : boolean = false
8890 ) {
8991 super ( ( ) => this . dispose ( ) ) ;
9092
@@ -103,7 +105,9 @@ export class Repository extends Disposable {
103105 this . normalizedPath = ( this . path . endsWith ( '/' ) ? this . path : `${ this . path } /` ) . toLowerCase ( ) ;
104106
105107 this . _suspended = suspended ;
108+ this . _closed = closed ;
106109
110+ // TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders
107111 const watcher = workspace . createFileSystemWatcher ( new RelativePattern ( folder , '{**/.git/config,**/.git/index,**/.git/HEAD,**/.git/refs/stash,**/.git/refs/heads/**,**/.git/refs/remotes/**,**/.git/refs/tags/**,**/.gitignore}' ) ) ;
108112 this . _disposable = Disposable . from (
109113 watcher ,
@@ -178,59 +182,21 @@ export class Repository extends Disposable {
178182 return ;
179183 }
180184
181- this . onAnyRepositoryChanged ( this ) ;
185+ this . onAnyRepositoryChanged ( this , RepositoryChange . Repository ) ;
182186 this . fireChange ( RepositoryChange . Repository ) ;
183187 }
184188
185- private fireChange ( ...reasons : RepositoryChange [ ] ) {
186- if ( this . _fireChangeDebounced === undefined ) {
187- this . _fireChangeDebounced = Functions . debounce ( this . fireChangeCore , 250 ) ;
188- }
189-
190- if ( this . _pendingChanges . repo === undefined ) {
191- this . _pendingChanges . repo = new RepositoryChangeEvent ( this ) ;
192- }
193-
194- const e = this . _pendingChanges . repo ;
195-
196- for ( const reason of reasons ) {
197- if ( ! e . changes . includes ( reason ) ) {
198- e . changes . push ( reason ) ;
199- }
200- }
201-
202- if ( this . _suspended ) return ;
203-
204- this . _fireChangeDebounced ( e ) ;
205- }
206-
207- private fireChangeCore ( e : RepositoryChangeEvent ) {
208- this . _pendingChanges . repo = undefined ;
209-
210- this . _onDidChange . fire ( e ) ;
189+ private _closed : boolean = false ;
190+ get closed ( ) : boolean {
191+ return this . _closed ;
211192 }
212-
213- private fireFileSystemChange ( uri : Uri ) {
214- if ( this . _fireFileSystemChangeDebounced === undefined ) {
215- this . _fireFileSystemChangeDebounced = Functions . debounce ( this . fireFileSystemChangeCore , 2500 ) ;
193+ set closed ( value : boolean ) {
194+ const changed = this . _closed !== value ;
195+ this . _closed = value ;
196+ if ( changed ) {
197+ this . onAnyRepositoryChanged ( this , RepositoryChange . Closed ) ;
198+ this . fireChange ( RepositoryChange . Closed ) ;
216199 }
217-
218- if ( this . _pendingChanges . fs === undefined ) {
219- this . _pendingChanges . fs = { repository : this , uris : [ ] } ;
220- }
221-
222- const e = this . _pendingChanges . fs ;
223- e . uris . push ( uri ) ;
224-
225- if ( this . _suspended ) return ;
226-
227- this . _fireFileSystemChangeDebounced ( e ) ;
228- }
229-
230- private fireFileSystemChangeCore ( e : RepositoryFileSystemChangeEvent ) {
231- this . _pendingChanges . fs = undefined ;
232-
233- this . _onDidChangeFileSystem . fire ( e ) ;
234200 }
235201
236202 containsUri ( uri : Uri ) {
@@ -313,6 +279,7 @@ export class Repository extends Disposable {
313279 this . _fsWatchCounter ++ ;
314280 if ( this . _fsWatcherDisposable !== undefined ) return ;
315281
282+ // TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders
316283 const watcher = workspace . createFileSystemWatcher ( new RelativePattern ( this . folder , `**` ) ) ;
317284 this . _fsWatcherDisposable = Disposable . from (
318285 watcher ,
@@ -333,4 +300,56 @@ export class Repository extends Disposable {
333300 suspend ( ) {
334301 this . _suspended = true ;
335302 }
303+
304+ private fireChange ( ...reasons : RepositoryChange [ ] ) {
305+ if ( this . _fireChangeDebounced === undefined ) {
306+ this . _fireChangeDebounced = Functions . debounce ( this . fireChangeCore , 250 ) ;
307+ }
308+
309+ if ( this . _pendingChanges . repo === undefined ) {
310+ this . _pendingChanges . repo = new RepositoryChangeEvent ( this ) ;
311+ }
312+
313+ const e = this . _pendingChanges . repo ;
314+
315+ for ( const reason of reasons ) {
316+ if ( ! e . changes . includes ( reason ) ) {
317+ e . changes . push ( reason ) ;
318+ }
319+ }
320+
321+ if ( this . _suspended ) return ;
322+
323+ this . _fireChangeDebounced ( e ) ;
324+ }
325+
326+ private fireChangeCore ( e : RepositoryChangeEvent ) {
327+ this . _pendingChanges . repo = undefined ;
328+
329+ this . _onDidChange . fire ( e ) ;
330+ }
331+
332+ private fireFileSystemChange ( uri : Uri ) {
333+ if ( this . _fireFileSystemChangeDebounced === undefined ) {
334+ this . _fireFileSystemChangeDebounced = Functions . debounce ( this . fireFileSystemChangeCore , 2500 ) ;
335+ }
336+
337+ if ( this . _pendingChanges . fs === undefined ) {
338+ this . _pendingChanges . fs = { repository : this , uris : [ ] } ;
339+ }
340+
341+ const e = this . _pendingChanges . fs ;
342+ e . uris . push ( uri ) ;
343+
344+ if ( this . _suspended ) return ;
345+
346+ this . _fireFileSystemChangeDebounced ( e ) ;
347+ }
348+
349+ private fireFileSystemChangeCore ( e : RepositoryFileSystemChangeEvent ) {
350+ this . _pendingChanges . fs = undefined ;
351+
352+ this . _onDidChangeFileSystem . fire ( e ) ;
353+ }
354+
336355}
0 commit comments