Skip to content

Commit 6564390

Browse files
committed
Merge pull request libgit2#1156 from libgit2/ptr1120-Repository.IsValid_should_only_throw_on_null_arguments
Make Repository.IsValid() return false on empty paths
2 parents 58056dc + dd8f6da commit 6564390

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)