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

Commit f81fb36

Browse files
committed
Warn if URL owner is different to current owner
Show different messages depending on whether the target URL owner is the same as the current repository owner.
1 parent 381806b commit f81fb36

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/GitHub.VisualStudio/Commands/OpenFromClipboardCommand.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace GitHub.VisualStudio.Commands
1111
public class OpenFromClipboardCommand : VsCommand<string>, IOpenFromClipboardCommand
1212
{
1313
public const string NoGitHubUrlMessage = "Couldn't a find a GitHub URL in clipboard";
14-
public const string NoResolveMessage = "Couldn't resolve Git object";
14+
public const string NoResolveSameOwnerMessage = "Couldn't find target URL in current repository. Try again after doing a fetch.";
15+
public const string NoResolveDifferentOwnerMessage = "The target URL has a different owner to the current repository.";
1516
public const string NoActiveRepositoryMessage = "There is no active repository to navigate";
1617
public const string ChangesInWorkingDirectoryMessage = "This file has changed since the permalink was created";
1718
public const string DifferentRepositoryMessage = "Please open the repository '{0}' and try again";
@@ -71,7 +72,15 @@ public override async Task Execute(string url)
7172
var (commitish, path, isSha) = gitHubContextService.Value.ResolveBlob(repositoryDir, context);
7273
if (path == null)
7374
{
74-
vsServices.Value.ShowMessageBoxInfo(NoResolveMessage);
75+
if (!string.Equals(activeRepository.Owner, context.Owner, StringComparison.OrdinalIgnoreCase))
76+
{
77+
vsServices.Value.ShowMessageBoxInfo(NoResolveDifferentOwnerMessage);
78+
}
79+
else
80+
{
81+
vsServices.Value.ShowMessageBoxInfo(NoResolveSameOwnerMessage);
82+
}
83+
7584
return;
7685
}
7786

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@ public async Task DifferentLocalRepository()
5252
vsServices.Received(1).ShowMessageBoxInfo(string.Format(OpenFromClipboardCommand.DifferentRepositoryMessage, context.RepositoryName));
5353
}
5454

55-
[Test]
56-
public async Task CouldNotResolve()
55+
[TestCase("TargetOwner", "CurrentOwner", OpenFromClipboardCommand.NoResolveDifferentOwnerMessage)]
56+
[TestCase("SameOwner", "SameOwner", OpenFromClipboardCommand.NoResolveSameOwnerMessage)]
57+
[TestCase("sameowner", "SAMEOWNER", OpenFromClipboardCommand.NoResolveSameOwnerMessage)]
58+
public async Task CouldNotResolve(string targetOwner, string currentOwner, string expectMessage)
5759
{
58-
var context = new GitHubContext();
60+
var context = new GitHubContext { Owner = targetOwner };
5961
var repositoryDir = "repositoryDir";
6062
(string, string, string)? resolveBlobResult = null;
6163
var vsServices = Substitute.For<IVSServices>();
6264
var target = CreateOpenFromClipboardCommand(vsServices: vsServices,
63-
contextFromClipboard: context, repositoryDir: repositoryDir, resolveBlobResult: resolveBlobResult);
65+
contextFromClipboard: context, repositoryDir: repositoryDir, repositoryOwner: currentOwner, resolveBlobResult: resolveBlobResult);
6466

6567
await target.Execute(null);
6668

67-
vsServices.Received(1).ShowMessageBoxInfo(OpenFromClipboardCommand.NoResolveMessage);
69+
vsServices.Received(1).ShowMessageBoxInfo(expectMessage);
6870
}
6971

7072
[Test]
@@ -136,6 +138,7 @@ static OpenFromClipboardCommand CreateOpenFromClipboardCommand(
136138
GitHubContext contextFromClipboard = null,
137139
string repositoryDir = null,
138140
string repositoryName = null,
141+
string repositoryOwner = null,
139142
string currentBranch = null,
140143
(string, string, string)? resolveBlobResult = null,
141144
bool? hasChanges = null)
@@ -148,6 +151,7 @@ static OpenFromClipboardCommand CreateOpenFromClipboardCommand(
148151
gitHubContextService.FindContextFromClipboard().Returns(contextFromClipboard);
149152
teamExplorerContext.ActiveRepository.LocalPath.Returns(repositoryDir);
150153
teamExplorerContext.ActiveRepository.Name.Returns(repositoryName);
154+
teamExplorerContext.ActiveRepository.Owner.Returns(repositoryOwner);
151155
teamExplorerContext.ActiveRepository.CurrentBranch.Name.Returns(currentBranch);
152156
if (resolveBlobResult != null)
153157
{

0 commit comments

Comments
 (0)