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

Commit 61ce000

Browse files
committed
Add method to find IGitRepositoriesExt
Stop relying on the state of IGitHubServiceProvider to locate IGitRepositoriesExt.
1 parent 21e6e3e commit 61ce000

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#endif
66

77
using System;
8+
using System.Threading;
89
using System.Collections.Generic;
910
using System.Diagnostics.CodeAnalysis;
1011
using System.ComponentModel.Composition;
11-
using System.Globalization;
1212
using System.Linq;
1313
using System.Reactive.Linq;
1414
using System.Threading.Tasks;
@@ -17,15 +17,12 @@
1717
using GitHub.Models;
1818
using GitHub.TeamFoundation;
1919
using GitHub.VisualStudio;
20-
#if TEAMEXPLORER14
20+
using Microsoft.TeamFoundation.Controls;
2121
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
22-
using ReactiveUI;
23-
#else
24-
using Microsoft.VisualStudio.Shell.Interop;
25-
using System.Threading;
26-
#endif
2722
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
23+
using ReactiveUI;
2824
using Serilog;
25+
using Microsoft;
2926

3027
namespace GitHub.Services
3128
{
@@ -81,8 +78,11 @@ public async Task Clone(
8178
bool recurseSubmodules,
8279
object progress = null)
8380
{
81+
var teamExplorer = serviceProvider.TryGetService<ITeamExplorer>();
82+
Assumes.Present(teamExplorer);
83+
8484
#if TEAMEXPLORER14
85-
var gitExt = serviceProvider.GetService<IGitRepositoriesExt>();
85+
var gitExt = await GetGitRepositoriesExtAsync(teamExplorer);
8686
gitExt.Clone(cloneUrl, clonePath, recurseSubmodules ? CloneOptions.RecurseSubmodule : CloneOptions.None);
8787

8888
// The operation will have completed when CanClone goes false and then true again.
@@ -100,6 +100,25 @@ await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.RunAsync(asy
100100
#endif
101101
}
102102

103+
static async Task<IGitRepositoriesExt> GetGitRepositoriesExtAsync(ITeamExplorer teamExplorer)
104+
{
105+
var connectPage = await NavigateToPageAsync(teamExplorer, new Guid(TeamExplorerPageIds.Connect));
106+
Assumes.Present(connectPage);
107+
var gitExt = connectPage.GetService<IGitRepositoriesExt>();
108+
Assumes.Present(gitExt);
109+
return gitExt;
110+
}
111+
112+
static async Task<ITeamExplorerPage> NavigateToPageAsync(ITeamExplorer teamExplorer, Guid pageId)
113+
{
114+
teamExplorer.NavigateToPage(pageId, null);
115+
var page = await teamExplorer
116+
.WhenAnyValue(x => x.CurrentPage)
117+
.Where(x => x?.GetId() == pageId)
118+
.Take(1);
119+
return page;
120+
}
121+
103122
IGitRepositoryInfo GetRepoFromVS()
104123
{
105124
gitExtService = serviceProvider.GetService<IGitExt>();

0 commit comments

Comments
 (0)