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

Commit 3228dc2

Browse files
committed
Fix tests
1 parent 2e2b5e0 commit 3228dc2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/GitHub.Exports/Models/SimpleRepositoryModel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ public void Refresh()
6464
/// <returns>An UriString with the generated url, or null if the repository has no remote server configured or if it can't be found locally</returns>
6565
public UriString GenerateUrl(string path = null, int startLine = -1, int endLine = -1)
6666
{
67-
var sha = HeadSha;
68-
if (CloneUrl == null || String.IsNullOrEmpty(sha))
67+
if (CloneUrl == null)
6968
return null;
7069

70+
var sha = HeadSha;
71+
// this also incidentally checks whether the repo has a valid LocalPath
72+
if (String.IsNullOrEmpty(sha))
73+
return CloneUrl.ToRepositoryUrl().AbsoluteUri;
74+
7175
if (path != null && Path.IsPathRooted(path))
7276
{
7377
// if the path root doesn't match the repository local path, then ignore it
74-
if (LocalPath == null ||
75-
!path.StartsWith(LocalPath, StringComparison.OrdinalIgnoreCase))
78+
if (!path.StartsWith(LocalPath, StringComparison.OrdinalIgnoreCase))
7679
{
7780
Debug.Assert(false, String.Format(CultureInfo.CurrentCulture, "GenerateUrl: path {0} doesn't match repository {1}", path, LocalPath));
7881
path = null;
@@ -81,7 +84,7 @@ public UriString GenerateUrl(string path = null, int startLine = -1, int endLine
8184
path = path.Substring(LocalPath.Length + 1);
8285
}
8386

84-
return new UriString(GenerateUrl(cloneUrl.ToRepositoryUrl().AbsoluteUri, sha, path, startLine, endLine));
87+
return new UriString(GenerateUrl(CloneUrl.ToRepositoryUrl().AbsoluteUri, sha, path, startLine, endLine));
8588
}
8689

8790
const string CommitFormat = "{0}/commit/{1}";

src/UnitTests/GitHub.Exports/SimpleRepositoryModelTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void SetupRepository(string sha)
4040
[InlineData(true, "https://github.com/foo/bar", "123123", @"src\dir\file1.cs", -1, 2, "https://github.com/foo/bar/blob/123123/src/dir/file1.cs")]
4141
[InlineData(true, "https://github.com/foo/bar", "", @"src\dir\file1.cs", -1, 2, "https://github.com/foo/bar")]
4242
[InlineData(true, null, "123123", @"src\dir\file1.cs", 1, 2, null)]
43+
[InlineData(false, "[email protected]/foo/bar", "123123", @"src\dir\file1.cs", -1, -1, "https://github.com/foo/bar/blob/123123/src/dir/file1.cs")]
4344
public void GenerateUrl(bool createRootedPath, string baseUrl, string sha, string path, int startLine, int endLine, string expected)
4445
{
4546
SetupRepository(sha);

0 commit comments

Comments
 (0)