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

Commit 92ffa39

Browse files
committed
Show message when there is no repo to navigate
Currently doesn't support opening/cloning repo so show message instead.
1 parent 5b16030 commit 92ffa39

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text.RegularExpressions;
99
using System.Runtime.InteropServices;
1010
using GitHub.Services;
11+
using GitHub.Extensions;
1112
using GitHub.Primitives;
1213
using Microsoft.VisualStudio;
1314
using Microsoft.VisualStudio.Shell;
@@ -308,6 +309,9 @@ public string ResolvePath(GitHubContext context)
308309

309310
public GitObject ResolveGitObject(string repositoryDir, GitHubContext context)
310311
{
312+
Guard.ArgumentNotNull(repositoryDir, nameof(repositoryDir));
313+
Guard.ArgumentNotNull(context, nameof(context));
314+
311315
using (var repository = gitService.GetRepository(repositoryDir))
312316
{
313317
var path = context.TreeishPath;

src/GitHub.VisualStudio/Commands/OpenFromClipboardCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class OpenFromClipboardCommand : VsCommand<string>, IOpenFromClipboardCom
1212
{
1313
public const string NoGitHubUrlMessage = "Couldn't a find a GitHub URL in clipboard";
1414
public const string NoResolveMessage = "Couldn't resolve Git object";
15+
public const string NoActiveRepositoryMessage = "There is no active repository to navigate";
1516

1617
readonly Lazy<IGitHubContextService> gitHubContextService;
1718
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
@@ -52,9 +53,9 @@ public override Task Execute(string url)
5253
}
5354

5455
var repositoryDir = teamExplorerContext.Value.ActiveRepository?.LocalPath;
55-
if (context == null)
56+
if (repositoryDir == null)
5657
{
57-
// No active repository
58+
vsServices.Value.ShowMessageBoxInfo(NoActiveRepositoryMessage);
5859
return Task.CompletedTask;
5960
}
6061

test/GitHub.VisualStudio.UnitTests/Commands/OpenFromClipboardCommandTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ public async Task NothingInClipboard()
2323
vsServices.Received(1).ShowMessageBoxInfo(OpenFromClipboardCommand.NoGitHubUrlMessage);
2424
}
2525

26+
[Test]
27+
public async Task NoLocalRepository()
28+
{
29+
var context = new GitHubContext();
30+
var repositoryDir = null as string;
31+
var vsServices = Substitute.For<IVSServices>();
32+
var target = CreateOpenFromClipboardCommand(vsServices: vsServices, contextFromClipboard: context, repositoryDir: repositoryDir);
33+
34+
await target.Execute(null);
35+
36+
vsServices.Received(1).ShowMessageBoxInfo(OpenFromClipboardCommand.NoActiveRepositoryMessage);
37+
}
38+
2639
[Test]
2740
public async Task CouldNotResolve()
2841
{

0 commit comments

Comments
 (0)