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

Commit cadf19a

Browse files
committed
Use GitHubContextService to navigate to files
When user clones a /blob/ type URL, navigate to the file after cloning/opening the repository.
1 parent 9175b2f commit cadf19a

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel.Composition;
4-
using System.IO;
54
using System.Linq;
65
using System.Reactive.Linq;
76
using System.Threading.Tasks;
87
using GitHub.Api;
8+
using GitHub.Exports;
99
using GitHub.Extensions;
1010
using GitHub.Helpers;
1111
using 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/>

src/GitHub.VisualStudio/Commands/OpenFromClipboardCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace GitHub.VisualStudio.Commands
1212
[Export(typeof(IOpenFromClipboardCommand))]
1313
public class OpenFromClipboardCommand : VsCommand<string>, IOpenFromClipboardCommand
1414
{
15-
16-
1715
readonly Lazy<IGitHubContextService> gitHubContextService;
1816
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
1917
readonly Lazy<IVSServices> vsServices;

0 commit comments

Comments
 (0)