Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter <peta1120@googlemail.com>2015-07-14 19:58:28 +0300
committernulltoken <emeric.fermas@gmail.com>2015-07-14 20:32:02 +0300
commitdd8f6da8b33a52995dccb597645a6e2f99e89565 (patch)
tree80c42c0386fe5462808b6457575705b2759938b5
parentb59c8a4077b3c0be2323375119aee51ce31e2c7c (diff)
Make Repository.IsValid() return false on empty paths
Fix #818
-rw-r--r--LibGit2Sharp.Tests/RepositoryFixture.cs20
-rw-r--r--LibGit2Sharp/Repository.cs7
2 files changed, 26 insertions, 1 deletions
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index 6f05029d..1828e977 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -57,6 +57,26 @@ namespace LibGit2Sharp.Tests
Assert.False(Repository.IsValid(scd.DirectoryPath));
}
+
+ [Fact]
+ public void IsValidWithNullPathThrows()
+ {
+ Assert.Throws<ArgumentNullException>(() => Repository.IsValid(null));
+ }
+
+ [Fact]
+ public void IsNotValidWithEmptyPath()
+ {
+ Assert.False(Repository.IsValid(string.Empty));
+ }
+
+ [Fact]
+ public void IsValidWithValidPath()
+ {
+ string repoPath = InitNewRepository();
+ Assert.True(Repository.IsValid(repoPath));
+ }
+
[Fact]
public void CanCreateStandardRepo()
{
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index bdf84e48..a3303d99 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -155,7 +155,12 @@ namespace LibGit2Sharp
/// <returns>True if a repository can be resolved through this path; false otherwise</returns>
static public bool IsValid(string path)
{
- Ensure.ArgumentNotNullOrEmptyString(path, "path");
+ Ensure.ArgumentNotNull(path, "path");
+
+ if (string.IsNullOrWhiteSpace(path))
+ {
+ return false;
+ }
try
{