diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f71d1e..9e7a944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#1332](https://github.com/eamodio/vscode-gitlens/issues/1332) - Stashes created with command line don't show up in the "Stashes" section - Fixes [#1045](https://github.com/eamodio/vscode-gitlens/issues/1045) - View File History not working - absolute path used — thanks to [PR #1334](https://github.com/eamodio/vscode-gitlens/pull/1334) by egfx-notifications ([@egfx-notifications](https://github.com/egfx-notifications)) - Fixes [#1323](https://github.com/eamodio/vscode-gitlens/issues/1323) - Interactive rebase hangs - Fixes [#1183](https://github.com/eamodio/vscode-gitlens/issues/1183) - stash all changes has no effect when the number of files is large diff --git a/src/git/gitService.ts b/src/git/gitService.ts index d7dbd26..cc9de2e 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -163,16 +163,7 @@ export class GitService implements Disposable { dispose() { this._repositoryTree.forEach(r => r.dispose()); - this._branchesCache.clear(); - this._contributorsCache.clear(); - this._mergeStatusCache.clear(); - this._rebaseStatusCache.clear(); - this._remotesWithApiProviderCache.clear(); - this._stashesCache.clear(); - this._tagsCache.clear(); - this._trackedCache.clear(); - this._userMapCache.clear(); - + void this.resetCaches(); this._disposable.dispose(); } @@ -618,6 +609,57 @@ export class GitService implements Disposable { } @log() + async resetCaches( + ...cache: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[] + ) { + if (cache.length === 0 || cache.includes('branches')) { + this._branchesCache.clear(); + + if (cache.length !== 0) { + for (const repo of await this.getRepositories()) { + repo.resetCaches('branch'); + } + } + } + + if (cache.length === 0 || cache.includes('contributors')) { + this._contributorsCache.clear(); + } + + if (cache.length === 0 || cache.includes('providers')) { + this._remotesWithApiProviderCache.clear(); + } + + if (cache.includes('remotes')) { + for (const repo of await this.getRepositories()) { + repo.resetCaches('remotes'); + } + } + + if (cache.length === 0 || cache.includes('stashes')) { + this._stashesCache.clear(); + } + + if (cache.length === 0 || cache.includes('status')) { + this._mergeStatusCache.clear(); + this._rebaseStatusCache.clear(); + } + + if (cache.length === 0 || cache.includes('tags')) { + this._tagsCache.clear(); + } + + if (cache.length === 0) { + this._trackedCache.clear(); + this._userMapCache.clear(); + + for (const repo of await this.getRepositories()) { + repo.resetCaches(); + } + } + } + + @log() async excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise { const paths = new Map(uris.map(u => [Strings.normalizePath(u.fsPath), u])); diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 8323888..75f6561 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -267,7 +267,7 @@ export class Repository implements Disposable { this._providers = RemoteProviderFactory.loadProviders(configuration.get('remotes', this.folder.uri)); if (!configuration.initializing(e)) { - this.resetRemotesCache(); + this.resetCaches('remotes'); this.fireChange(RepositoryChange.Remotes); } } @@ -291,8 +291,7 @@ export class Repository implements Disposable { } if (uri.path.endsWith('.git/config')) { - this._branch = undefined; - this.resetRemotesCache(); + this.resetCaches(); this.fireChange(RepositoryChange.Config, RepositoryChange.Remotes); return; @@ -305,7 +304,7 @@ export class Repository implements Disposable { } if (uri.path.endsWith('.git/HEAD') || uri.path.endsWith('.git/ORIG_HEAD')) { - this._branch = undefined; + this.resetCaches('branch'); this.fireChange(RepositoryChange.Heads); return; @@ -327,13 +326,12 @@ export class Repository implements Disposable { if (match != null) { switch (match[1]) { case 'heads': - this._branch = undefined; + this.resetCaches('branch'); this.fireChange(RepositoryChange.Heads); return; case 'remotes': - this._branch = undefined; - this.resetRemotesCache(); + this.resetCaches(); this.fireChange(RepositoryChange.Remotes); return; @@ -562,12 +560,6 @@ export class Repository implements Disposable { return Container.git.getRichRemoteProvider(await this.getRemotes(), { includeDisconnected: !connectedOnly }); } - private resetRemotesCache() { - this._remotes = undefined; - this._remotesDisposable?.dispose(); - this._remotesDisposable = undefined; - } - private async subscribeToRemotes(remotes: Promise) { this._remotesDisposable?.dispose(); this._remotesDisposable = undefined; @@ -735,6 +727,18 @@ export class Repository implements Disposable { this.runTerminalCommand('reset', ...args); } + resetCaches(...cache: ('branch' | 'remotes')[]) { + if (cache.length === 0 || cache.includes('branch')) { + this._branch = undefined; + } + + if (cache.length === 0 || cache.includes('remotes')) { + this._remotes = undefined; + this._remotesDisposable?.dispose(); + this._remotesDisposable = undefined; + } + } + resume() { if (!this._suspended) return; @@ -778,9 +782,7 @@ export class Repository implements Disposable { async stashApply(stashName: string, options: { deleteAfter?: boolean } = {}) { void (await Container.git.stashApply(this.path, stashName, options)); - if (!this.supportsChangeEvents) { - this.fireChange(RepositoryChange.Stash); - } + this.fireChange(RepositoryChange.Stash); } @gate(() => '') @@ -788,9 +790,7 @@ export class Repository implements Disposable { async stashDelete(stashName: string, ref?: string) { void (await Container.git.stashDelete(this.path, stashName, ref)); - if (!this.supportsChangeEvents) { - this.fireChange(RepositoryChange.Stash); - } + this.fireChange(RepositoryChange.Stash); } @gate(() => '') @@ -798,9 +798,7 @@ export class Repository implements Disposable { async stashSave(message?: string, uris?: Uri[], options: { includeUntracked?: boolean; keepIndex?: boolean } = {}) { void (await Container.git.stashSave(this.path, message, uris, options)); - if (!this.supportsChangeEvents) { - this.fireChange(RepositoryChange.Stash); - } + this.fireChange(RepositoryChange.Stash); } @gate() @@ -1003,9 +1001,7 @@ export class Repository implements Disposable { const parsedArgs = args.map(arg => (arg.startsWith('#') ? `"${arg}"` : arg)); runGitCommandInTerminal(command, parsedArgs.join(' '), this.path, true); - if (!this.supportsChangeEvents) { - setTimeout(() => this.fireChange(RepositoryChange.Unknown), 2500); - } + setTimeout(() => this.fireChange(RepositoryChange.Unknown), 2500); } private async tryWatchingForChangesViaBuiltInApi() { diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 563d74b..8119f95 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -153,7 +153,14 @@ export class BranchesView extends ViewBase () => commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setLayoutToList'), () => this.setLayout(ViewBranchesLayout.List), diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index de2d6be..f4b2f09 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -294,7 +294,14 @@ export class CommitsView extends ViewBase { () => commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'status', 'tags'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setFilesLayoutToAuto'), () => this.setFilesLayout(ViewFilesLayout.Auto), diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index f7ba585..3fa148e 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -132,7 +132,14 @@ export class ContributorsView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('contributors'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setFilesLayoutToAuto'), () => this.setFilesLayout(ViewFilesLayout.Auto), diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index 1eed315..d86a315 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -148,7 +148,14 @@ export class RemotesView extends ViewBase { () => commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'remotes'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setLayoutToList'), () => this.setLayout(ViewBranchesLayout.List), diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 95cc4cb..355a3b9 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -69,7 +69,14 @@ export class RepositoriesView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'contributors', 'remotes', 'stashes', 'status', 'tags'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setBranchesLayoutToList'), () => this.setBranchesLayout(ViewBranchesLayout.List), diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index 9bbd41b..f3bab5e 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -130,7 +130,14 @@ export class StashesView extends ViewBase { () => commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('stashes'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setFilesLayoutToAuto'), () => this.setFilesLayout(ViewFilesLayout.Auto), diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index b04b84c..bd1969d 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -137,7 +137,14 @@ export class TagsView extends ViewBase { () => commands.executeCommand('gitlens.views.copy', this.selection), this, ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('tags'); + return this.refresh(true); + }, + this, + ); commands.registerCommand( this.getQualifiedCommand('setLayoutToList'), () => this.setLayout(ViewBranchesLayout.List),