diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index b240d2a..ed91f00 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -726,19 +726,21 @@ export class Repository implements Disposable { await Container.context.workspaceState.update(WorkspaceState.StarredRepositories, starred); } - startWatchingFileSystem() { + startWatchingFileSystem(): Disposable { this._fsWatchCounter++; - if (this._fsWatcherDisposable != null) return; + if (this._fsWatcherDisposable == null) { + // TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders + // https://github.com/Microsoft/vscode/issues/3025 + const watcher = workspace.createFileSystemWatcher(new RelativePattern(this.folder, '**')); + this._fsWatcherDisposable = Disposable.from( + watcher, + watcher.onDidChange(this.onFileSystemChanged, this), + watcher.onDidCreate(this.onFileSystemChanged, this), + watcher.onDidDelete(this.onFileSystemChanged, this), + ); + } - // TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders - // https://github.com/Microsoft/vscode/issues/3025 - const watcher = workspace.createFileSystemWatcher(new RelativePattern(this.folder, '**')); - this._fsWatcherDisposable = Disposable.from( - watcher, - watcher.onDidChange(this.onFileSystemChanged, this), - watcher.onDidCreate(this.onFileSystemChanged, this), - watcher.onDidDelete(this.onFileSystemChanged, this), - ); + return { dispose: () => this.stopWatchingFileSystem() }; } stopWatchingFileSystem() { diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 4094356..4f7f677 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -132,11 +132,9 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi const subscription = Disposable.from( repo.onDidChange(this.onRepoChanged, this), repo.onDidChangeFileSystem(this.onRepoFileSystemChanged, this), - { dispose: () => repo.stopWatchingFileSystem() }, + repo.startWatchingFileSystem(), ); - repo.startWatchingFileSystem(); - return subscription; } diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 0286557..cc06271 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -262,11 +262,9 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi const subscription = Disposable.from( repo.onDidChange(this.onRepoChanged, this), repo.onDidChangeFileSystem(this.onRepoFileSystemChanged, this), - { dispose: () => repo.stopWatchingFileSystem() }, + repo.startWatchingFileSystem(), ); - repo.startWatchingFileSystem(); - return subscription; } diff --git a/src/views/nodes/repositoryNode.ts b/src/views/nodes/repositoryNode.ts index 075eb41..5dc219d 100644 --- a/src/views/nodes/repositoryNode.ts +++ b/src/views/nodes/repositoryNode.ts @@ -248,11 +248,10 @@ export class RepositoryNode extends SubscribeableViewNode { // } if (this.includeWorkingTree) { - disposables.push(this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), { - dispose: () => this.repo.stopWatchingFileSystem(), - }); - - this.repo.startWatchingFileSystem(); + disposables.push( + this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), + this.repo.startWatchingFileSystem(), + ); } return Disposable.from(...disposables);