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

Commit c175d97

Browse files
committed
Don't throw when navigating to non-blob
1 parent bc780c4 commit c175d97

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,19 @@ public string ResolvePath(GitHubContext context)
308308

309309
using (var repository = gitService.GetRepository(repositoryDir))
310310
{
311-
var objectishPath = context.TreeishPath;
312-
if (context.BlobName != null)
311+
if (context.TreeishPath == null)
313312
{
314-
objectishPath += '/' + context.BlobName;
313+
// Blobs without a TreeishPath aren't currently supported
314+
return (null, null);
315315
}
316316

317+
if (context.BlobName == null)
318+
{
319+
// Not a blob
320+
return (null, null);
321+
}
322+
323+
var objectishPath = $"{context.TreeishPath}/{context.BlobName}";
317324
foreach (var objectish in ToObjectish(objectishPath))
318325
{
319326
var commit = repository.Lookup(objectish.commitish);

test/GitHub.App.UnitTests/Services/GitHubContextServiceTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ public class TheResolveGitObjectMethod
330330
[TestCase("https://github.com/github/VisualStudio/blob/branch-name/src/foo.cs", "branch-name", "branch-name:src/foo.cs", "branch-name", "src/foo.cs")]
331331
[TestCase("https://github.com/github/VisualStudio/blob/fixes/666-bug/src/foo.cs", "fixes/666-bug", "fixes/666-bug:src/foo.cs", "fixes/666-bug", "src/foo.cs")]
332332
[TestCase("https://github.com/github/VisualStudio/blob/fixes/666-bug/A/B/foo.cs", "fixes/666-bug", "fixes/666-bug:A/B/foo.cs", "fixes/666-bug", "A/B/foo.cs")]
333-
[TestCase("https://github.com/github/VisualStudio/blob/master/foo.cs", "master", "", "master", null, Description = "Resolve commit only")]
333+
[TestCase("https://github.com/github/VisualStudio/blob/master/foo.cs", "master", null, "master", null, Description = "Resolve commit only")]
334+
[TestCase("https://github.com/github/VisualStudio/commit/8cf9a268c497adb4fc0a14572253165e179dd11e", "8cf9a268c497adb4fc0a14572253165e179dd11e", null, null, null)]
334335
public void ResolveGitObject(string url, string commitish, string objectish, string expectCommitish, string expectPath)
335336
{
336337
var repositoryDir = "repositoryDir";

0 commit comments

Comments
 (0)