Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 67f9b6d

Browse files
committed
Initialize VSGitExt in UICONTEXT.RepositoryOpen
We can be more precise and only initialize VSGitExt when in the RepositoryOpen UIContext rather than the GitSccProvider UIContext.
1 parent d55e27b commit 67f9b6d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.VisualStudio.Threading;
1313
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
1414
using Task = System.Threading.Tasks.Task;
15+
using static Microsoft.VisualStudio.VSConstants;
1516

1617
namespace GitHub.VisualStudio.Base
1718
{
@@ -51,9 +52,8 @@ public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory
5152
// Start with empty array until we have a chance to initialize.
5253
ActiveRepositories = Array.Empty<ILocalRepositoryModel>();
5354

54-
// The IGitExt service isn't available when a TFS based solution is opened directly.
55-
// It will become available when moving to a Git based solution (and cause a UIContext event to fire).
56-
var context = factory.GetUIContext(new Guid(Guids.GitSccProviderId));
55+
// Initialize when we enter the context of a Git repository
56+
var context = factory.GetUIContext(UICONTEXT.RepositoryOpen_guid);
5757
context.WhenActivated(() => JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log));
5858
}
5959

test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
using Microsoft.VisualStudio.Shell;
1414
using Microsoft.VisualStudio.Threading;
1515
using Task = System.Threading.Tasks.Task;
16+
using static Microsoft.VisualStudio.VSConstants;
1617

1718
public class VSGitExtTests
1819
{
1920
public class TheConstructor : TestBaseClass
2021
{
2122
[TestCase(true, 1)]
2223
[TestCase(false, 0)]
23-
public void GetServiceIGitExt_WhenSccProviderContextIsActive(bool isActive, int expectCalls)
24+
public void GetServiceIGitExt_WhenRepositoryOpenIsActive(bool isActive, int expectCalls)
2425
{
2526
var context = CreateVSUIContext(isActive);
2627
var sp = Substitute.For<IAsyncServiceProvider>();
@@ -135,7 +136,7 @@ public void WhenUIContextChanged_FiredUsingThreadPoolThread()
135136
public class TheActiveRepositoriesProperty : TestBaseClass
136137
{
137138
[Test]
138-
public void SccProviderContextNotActive_IsEmpty()
139+
public void RepositoryOpenContextNotActive_IsEmpty()
139140
{
140141
var context = CreateVSUIContext(false);
141142
var target = CreateVSGitExt(context);
@@ -144,7 +145,7 @@ public void SccProviderContextNotActive_IsEmpty()
144145
}
145146

146147
[Test]
147-
public void SccProviderContextIsActive_InitializeWithActiveRepositories()
148+
public void RepositoryOpenIsActive_InitializeWithActiveRepositories()
148149
{
149150
var repoPath = "repoPath";
150151
var repoFactory = Substitute.For<ILocalRepositoryModelFactory>();
@@ -217,8 +218,7 @@ static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = nul
217218
repoFactory = repoFactory ?? Substitute.For<ILocalRepositoryModelFactory>();
218219
joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext();
219220
var factory = Substitute.For<IVSUIContextFactory>();
220-
var contextGuid = new Guid(Guids.GitSccProviderId);
221-
factory.GetUIContext(contextGuid).Returns(context);
221+
factory.GetUIContext(UICONTEXT.RepositoryOpen_guid).Returns(context);
222222
sp.GetServiceAsync(typeof(IGitExt)).Returns(gitExt);
223223
var vsGitExt = new VSGitExt(sp, factory, repoFactory, joinableTaskContext);
224224
vsGitExt.JoinTillEmpty();

0 commit comments

Comments
 (0)