From a97ce7995c86348dc15e2ddb4aec9128bdb9a612 Mon Sep 17 00:00:00 2001 From: Nigel Westbury Date: Mon, 21 Oct 2019 17:18:06 +0100 Subject: [PATCH] Fixes to default selected SCM code Signed-off-by: Nigel Westbury --- packages/git/src/browser/git-repository-provider.ts | 9 +++++++-- packages/scm/src/browser/scm-service.ts | 5 +---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/git/src/browser/git-repository-provider.ts b/packages/git/src/browser/git-repository-provider.ts index 6bb5563d633ab..0d7dc94832092 100644 --- a/packages/git/src/browser/git-repository-provider.ts +++ b/packages/git/src/browser/git-repository-provider.ts @@ -87,10 +87,15 @@ export class GitRepositoryProvider { } /** - * Sets or un-sets the repository. + * Sets the selected repository, but do nothing if the given repository is not a Git repository + * registered with the SCM service. We must be sure not to clear the selection if the selected + * repository is managed by an SCM other than Git. */ set selectedRepository(repository: Repository | undefined) { - this.scmService.selectedRepository = this.toScmRepository(repository); + const scmRepository = this.toScmRepository(repository); + if (scmRepository) { + this.scmService.selectedRepository = scmRepository; + } } get selectedScmRepository(): GitScmRepository | undefined { diff --git a/packages/scm/src/browser/scm-service.ts b/packages/scm/src/browser/scm-service.ts index 174efbd77bd0c..89429527ade6c 100644 --- a/packages/scm/src/browser/scm-service.ts +++ b/packages/scm/src/browser/scm-service.ts @@ -65,9 +65,6 @@ export class ScmService { } this.toDisposeOnSelected.dispose(); this._selectedRepository = repository; - if (!repository) { - this._selectedRepository = this._repositories.values().next().value; - } this.updateContextKeys(); if (this._selectedRepository) { this.toDisposeOnSelected.push(this._selectedRepository.onDidChange(() => this.updateContextKeys())); @@ -91,7 +88,7 @@ export class ScmService { dispose.bind(repository)(); this.onDidRemoveRepositoryEmitter.fire(repository); if (this._selectedRepository === repository) { - this.selectedRepository = undefined; + this.selectedRepository = this._repositories.values().next().value; } }; this._repositories.set(key, repository);