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

Commit 763533b

Browse files
committed
Merge branch 'fixes/1924-use-GitSccProvider-UIContext' into test/integration-tests
2 parents 67815ea + 0777f44 commit 763533b

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
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;
1615

1716
namespace GitHub.VisualStudio.Base
1817
{
@@ -52,9 +51,15 @@ public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory
5251
// Start with empty array until we have a chance to initialize.
5352
ActiveRepositories = Array.Empty<ILocalRepositoryModel>();
5453

55-
// Initialize when we enter the context of a Git repository
56-
var context = factory.GetUIContext(UICONTEXT.RepositoryOpen_guid);
57-
context.WhenActivated(() => JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log));
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+
// NOTE: I tried using the RepositoryOpen context, but it didn't work consistently.
57+
var context = factory.GetUIContext(new Guid(Guids.GitSccProviderId));
58+
context.WhenActivated(() =>
59+
{
60+
log.Debug("WhenActivated");
61+
JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log);
62+
});
5863
}
5964

6065
async Task InitializeAsync()

test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ public class VSGitExtTests
1919
{
2020
public class TheConstructor : TestBaseClass
2121
{
22-
[TestCase(true, 1)]
23-
[TestCase(false, 0)]
24-
public void GetServiceIGitExt_WhenRepositoryOpenIsActive(bool isActive, int expectCalls)
22+
[TestCase(true, Guids.GitSccProviderId, 1)]
23+
[TestCase(true, UICONTEXT.RepositoryOpen_string, 0, Description = "No longer using RepositoryOpen")]
24+
[TestCase(false, Guids.GitSccProviderId, 0)]
25+
public void GetServiceIGitExt_WhenGitSccProviderIsActive(bool isActive, string contextGuidString, int expectCalls)
2526
{
2627
var context = CreateVSUIContext(isActive);
2728
var sp = Substitute.For<IAsyncServiceProvider>();
2829

29-
var target = CreateVSGitExt(context, sp: sp);
30+
var target = CreateVSGitExt(context, sp: sp, contextGuidString: contextGuidString);
3031

3132
sp.Received(expectCalls).GetServiceAsync(typeof(IGitExt));
3233
}
@@ -210,15 +211,16 @@ static IReadOnlyList<IGitRepositoryInfo> CreateActiveRepositories(params string[
210211
}
211212

212213
static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = null, IAsyncServiceProvider sp = null,
213-
ILocalRepositoryModelFactory repoFactory = null, JoinableTaskContext joinableTaskContext = null)
214+
ILocalRepositoryModelFactory repoFactory = null, JoinableTaskContext joinableTaskContext = null, string contextGuidString = null)
214215
{
215216
context = context ?? CreateVSUIContext(true);
216217
gitExt = gitExt ?? CreateGitExt();
218+
var contextGuid = new Guid(contextGuidString ?? Guids.GitSccProviderId);
217219
sp = sp ?? Substitute.For<IAsyncServiceProvider>();
218220
repoFactory = repoFactory ?? Substitute.For<ILocalRepositoryModelFactory>();
219221
joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext();
220222
var factory = Substitute.For<IVSUIContextFactory>();
221-
factory.GetUIContext(UICONTEXT.RepositoryOpen_guid).Returns(context);
223+
factory.GetUIContext(contextGuid).Returns(context);
222224
sp.GetServiceAsync(typeof(IGitExt)).Returns(gitExt);
223225
var vsGitExt = new VSGitExt(sp, factory, repoFactory, joinableTaskContext);
224226
vsGitExt.JoinTillEmpty();

0 commit comments

Comments
 (0)