8000 Make Repository.IsValid() return false on empty paths · libgit2/libgit2sharp@dd8f6da · GitHub
[go: up one dir, main page]

Skip to content

Commit dd8f6da

Browse files
ptr1120nulltoken
authored andcommitted
Make Repository.IsValid() return false on empty paths
Fix #818
1 parent b59c8a4 commit dd8f6da

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ public void CanCheckIfADirectoryLeadsToAValidRepository()
5757
Assert.False(Repository.IsValid(scd.DirectoryPath));
5858
}
5959

60+
61+
[Fact]
62+
public void IsValidWithNullPathThrows()
63+
{
64+
Assert.Throws<ArgumentNullException>(() => Repository.IsValid(null));
65+
}
66+
67+
[Fact]
68+
public void IsNotValidWithEmptyPath()
69+
{
70+
Assert.False(Repository.IsValid(string.Empty));
71+
}
72+
73+
[Fact]
74+
public void IsValidWithValidPath()
75+
{
76+
string repoPath = InitNewRepository();
77+
Assert.True(Repository.IsValid(repoPath));
78+
}
79+
6080
[Fact]
6181
public void CanCreateStandardRepo()
6282
{

LibGit2Sharp/Repository.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ public Repository(string path, RepositoryOptions options)
155155
/// <returns>True if a repository can be resolved through this path; false otherwise</returns>
156156
static public bool IsValid(string path)
157157
{
158-
Ensure.ArgumentNotNullOrEmptyString(path, "path");
158+
Ensure.ArgumentNotNull(path, "path");
159+
160+
if (string.IsNullOrWhiteSpace(path))
161+
{
162+
return false;
163+
}
159164

160165
try
161166
{

0 commit comments

Comments
 (0)
0