11using System ;
22using System . Collections . Generic ;
33using System . ComponentModel . Composition ;
4- using System . IO ;
54using System . Linq ;
65using System . Reactive . Linq ;
76using System . Threading . Tasks ;
87using GitHub . Api ;
8+ using GitHub . Exports ;
99using GitHub . Extensions ;
1010using GitHub . Helpers ;
1111using GitHub . Logging ;
@@ -36,6 +36,8 @@ public class RepositoryCloneService : IRepositoryCloneService
3636 readonly IVSGitServices vsGitServices ;
3737 readonly ITeamExplorerServices teamExplorerServices ;
3838 readonly IGraphQLClientFactory graphqlFactory ;
39+ readonly IGitHubContextService gitHubContextService ;
40+ readonly IVSServices vsServices ;
3941 readonly IUsageTracker usageTracker ;
4042 ICompiledQuery < ViewerRepositoriesModel > readViewerRepositories ;
4143
@@ -45,12 +47,16 @@ public RepositoryCloneService(
4547 IVSGitServices vsGitServices ,
4648 ITeamExplorerServices teamExplorerServices ,
4749 IGraphQLClientFactory graphqlFactory ,
50+ IGitHubContextService gitHubContextService ,
51+ IVSServices vsServices ,
4852 IUsageTracker usageTracker )
4953 {
5054 this . operatingSystem = operatingSystem ;
5155 this . vsGitServices = vsGitServices ;
5256 this . teamExplorerServices = teamExplorerServices ;
5357 this . graphqlFactory = graphqlFactory ;
58+ this . gitHubContextService = gitHubContextService ;
59+ this . vsServices = vsServices ;
5460 this . usageTracker = usageTracker ;
5561
5662 defaultClonePath = GetLocalClonePathFromGitProvider ( operatingSystem . Environment . GetUserRepositoriesPath ( ) ) ;
@@ -153,6 +159,21 @@ public async Task CloneOrOpenRepository(
153159
154160 // Give user a chance to choose a solution
155161 teamExplorerServices . ShowHomePage ( ) ;
162+
163+ var context = gitHubContextService . FindContextFromUrl ( url ) ;
164+ if ( context . LinkType == LinkType . Blob )
165+ {
166+ // Navigate to file for /blob/ type URLs
167+ var ( commitish , path , isSha ) = gitHubContextService . ResolveBlob ( repositoryPath , context ) ;
168+
169+ var hasChanges = gitHubContextService . HasChangesInWorkingDirectory ( repositoryPath , commitish , path ) ;
170+ if ( hasChanges )
171+ {
172+ vsServices . ShowMessageBoxInfo ( Resources . ChangesInWorkingDirectoryMessage ) ;
173+ }
174+
175+ gitHubContextService . TryOpenFile ( repositoryPath , context ) ;
176+ }
156177 }
157178
158179 /// <inheritdoc/>
0 commit comments