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

Commit c5c493d

Browse files
committed
Warn when user isn't in target repository
Warn when a user attempts to navigate to a repository that isn't currently open.
1 parent 11866fb commit c5c493d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/GitHub.VisualStudio/Commands/OpenFromClipboardCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class OpenFromClipboardCommand : VsCommand<string>, IOpenFromClipboardCom
1414
public const string NoResolveMessage = "Couldn't resolve Git object";
1515
public const string NoActiveRepositoryMessage = "There is no active repository to navigate";
1616
public const string ChangesInWorkingDirectoryMessage = "This file has changed since the permalink was created";
17+
public const string DifferentRepositoryMessage = "Please open the repository '{0}' and try again";
1718

1819
readonly Lazy<IGitHubContextService> gitHubContextService;
1920
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
@@ -61,6 +62,12 @@ public override async Task Execute(string url)
6162
return;
6263
}
6364

65+
if (activeRepository.Name != context.RepositoryName)
66+
{
67+
vsServices.Value.ShowMessageBoxInfo(string.Format(DifferentRepositoryMessage, context.RepositoryName));
68+
return;
69+
}
70+
6471
var (commitish, path) = gitHubContextService.Value.ResolveBlob(repositoryDir, context);
6572
if (path == null)
6673
{

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public async Task NoLocalRepository()
3535
vsServices.Received(1).ShowMessageBoxInfo(OpenFromClipboardCommand.NoActiveRepositoryMessage);
3636
}
3737

38+
[Test]
39+
public async Task DifferentLocalRepository()
40+
{
41+
var targetRepositoryName = "targetRepositoryName";
42+
var activeRepositoryName = "activeRepositoryName";
43+
var activeRepositoryDir = "activeRepositoryDir";
44+
var context = new GitHubContext { RepositoryName = targetRepositoryName };
45+
(string, string)? gitObject = null;
46+
var vsServices = Substitute.For<IVSServices>();
47+
var target = CreateOpenFromClipboardCommand(vsServices: vsServices,
48+
contextFromClipboard: context, repositoryDir: activeRepositoryDir, repositoryName: activeRepositoryName, gitObject: gitObject);
49+
50+
await target.Execute(null);
51+
52+
vsServices.Received(1).ShowMessageBoxInfo(string.Format(OpenFromClipboardCommand.DifferentRepositoryMessage, context.RepositoryName));
53+
}
54+
3855
[Test]
3956
public async Task CouldNotResolve()
4057
{
@@ -118,6 +135,7 @@ static OpenFromClipboardCommand CreateOpenFromClipboardCommand(
118135
IVSServices vsServices = null,
119136
GitHubContext contextFromClipboard = null,
120137
string repositoryDir = null,
138+
string repositoryName = null,
121139
string currentBranch = null,
122140
(string, string)? gitObject = null,
123141
bool? hasChanges = null)
@@ -129,6 +147,7 @@ static OpenFromClipboardCommand CreateOpenFromClipboardCommand(
129147

130148
gitHubContextService.FindContextFromClipboard().Returns(contextFromClipboard);
131149
teamExplorerContext.ActiveRepository.LocalPath.Returns(repositoryDir);
150+
teamExplorerContext.ActiveRepository.Name.Returns(repositoryName);
132151
teamExplorerContext.ActiveRepository.CurrentBranch.Name.Returns(currentBranch);
133152
if (gitObject != null)
134153
{

0 commit comments

Comments
 (0)