55#endif
66
77using System ;
8+ using System . Threading ;
89using System . Collections . Generic ;
910using System . Diagnostics . CodeAnalysis ;
1011using System . ComponentModel . Composition ;
11- using System . Globalization ;
1212using System . Linq ;
1313using System . Reactive . Linq ;
1414using System . Threading . Tasks ;
1717using GitHub . Models ;
1818using GitHub . TeamFoundation ;
1919using GitHub . VisualStudio ;
20- #if TEAMEXPLORER14
20+ using Microsoft . TeamFoundation . Controls ;
2121using Microsoft . TeamFoundation . Git . Controls . Extensibility ;
22- using ReactiveUI ;
23- #else
24- using Microsoft . VisualStudio . Shell . Interop ;
25- using System . Threading ;
26- #endif
2722using Microsoft . VisualStudio . TeamFoundation . Git . Extensibility ;
23+ using ReactiveUI ;
2824using Serilog ;
25+ using Microsoft ;
2926
3027namespace 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