Skip to content

Make Repository.IsValid() return false on empty paths #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ public void CanCheckIfADirectoryLeadsToAValidRepository()
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()
{
Expand Down
7 changes: 6 additions & 1 deletion LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ public Repository(string path, RepositoryOptions options)
/// <returns>True if a repository can be resolved through this path; false otherwise</returns>
static public bool IsValid(string path)
{
Ensure.ArgumentNotNullOrEmptyString(path, "path");
// should only throw on null arguments
Ensure.ArgumentNotNull(path, "path");
if (string.IsNullOrWhiteSpace(path))
{
return false;
}

try
{
Expand Down