@@ -36,7 +36,9 @@ public class RepositoryCloneService : IRepositoryCloneService
3636 readonly IVSGitServices vsGitServices ;
3737 readonly ITeamExplorerServices teamExplorerServices ;
3838 readonly IGraphQLClientFactory graphqlFactory ;
39+ readonly IGitHubContextService gitHubContextService ;
3940 readonly IUsageTracker usageTracker ;
41+ readonly Lazy < EnvDTE . DTE > dte ;
4042 ICompiledQuery < ViewerRepositoriesModel > readViewerRepositories ;
4143
4244 [ ImportingConstructor ]
@@ -45,13 +47,17 @@ public RepositoryCloneService(
4547 IVSGitServices vsGitServices ,
4648 ITeamExplorerServices teamExplorerServices ,
4749 IGraphQLClientFactory graphqlFactory ,
48- IUsageTracker usageTracker )
50+ IGitHubContextService gitHubContextService ,
51+ IUsageTracker usageTracker ,
52+ IGitHubServiceProvider sp )
4953 {
5054 this . operatingSystem = operatingSystem ;
5155 this . vsGitServices = vsGitServices ;
5256 this . teamExplorerServices = teamExplorerServices ;
5357 this . graphqlFactory = graphqlFactory ;
58+ this . gitHubContextService = gitHubContextService ;
5459 this . usageTracker = usageTracker ;
60+ dte = new Lazy < EnvDTE . DTE > ( ( ) => sp . GetService < EnvDTE . DTE > ( ) ) ;
5561
5662 defaultClonePath = GetLocalClonePathFromGitProvider ( operatingSystem . Environment . GetUserRepositoriesPath ( ) ) ;
5763 }
@@ -125,7 +131,10 @@ public async Task CloneOrOpenRepository(
125131 var isDotCom = HostAddress . IsGitHubDotComUri ( repositoryUrl ) ;
126132 if ( DestinationDirectoryExists ( repositoryPath ) )
127133 {
128- teamExplorerServices . OpenRepository ( repositoryPath ) ;
134+ if ( ! IsSolutionInRepository ( repositoryPath ) )
135+ {
136+ teamExplorerServices . OpenRepository ( repositoryPath ) ;
137+ }
129138
130139 if ( isDotCom )
131140 {
@@ -153,6 +162,36 @@ public async Task CloneOrOpenRepository(
153162
154163 // Give user a chance to choose a solution
155164 teamExplorerServices . ShowHomePage ( ) ;
165+
166+ // Navigate to context for supported URL types (e.g. /blob/ URLs)
167+ var context = gitHubContextService . FindContextFromUrl ( url ) ;
168+ if ( context != null )
169+ {
170+ gitHubContextService . TryNavigateToContext ( repositoryPath , context ) ;
171+ }
172+ }
173+
174+ bool IsSolutionInRepository ( string repositoryPath )
175+ {
176+ var solutionPath = dte . Value . Solution . FileName ;
177+ if ( string . IsNullOrEmpty ( solutionPath ) )
178+ {
179+ return false ;
180+ }
181+
182+ var isFolder = operatingSystem . Directory . DirectoryExists ( solutionPath ) ;
183+ var solutionDir = isFolder ? solutionPath : Path . GetDirectoryName ( solutionPath ) ;
184+ if ( string . Equals ( repositoryPath , solutionDir , StringComparison . OrdinalIgnoreCase ) )
185+ {
186+ return true ;
187+ }
188+
189+ if ( solutionDir . StartsWith ( repositoryPath + '\\ ' , StringComparison . OrdinalIgnoreCase ) )
190+ {
191+ return true ;
192+ }
193+
194+ return false ;
156195 }
157196
158197 /// <inheritdoc/>
0 commit comments