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:
authorArkadiy Shapkin <ashapkin@artec-group.com>2013-04-15 01:56:30 +0400
committerArkadiy Shapkin <ashapkin@artec-group.com>2013-04-17 20:16:57 +0400
commit98a708ff3433d989415982b7ab824ed2b0f88ab5 (patch)
tree5a8a99ed59880476d039bcd24df554e85c70bda2 /LibGit2Sharp/Repository.cs
parent21696b88718ca8b37f68bc6db022a303daf32056 (diff)
Simple function added that check is valid git repository path without initializing it
NullRepositorySafeHandle based proposal
Diffstat (limited to 'LibGit2Sharp/Repository.cs')
-rw-r--r--LibGit2Sharp/Repository.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 37e58e35..e79a8267 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -130,6 +130,30 @@ namespace LibGit2Sharp
}
}
+ /// <summary>
+ /// Check if parameter <paramref name="path"/> leads to a valid git repository.
+ /// </summary>
+ /// <param name = "path">
+ /// The path to the git repository to check, can be either the path to the git directory (for non-bare repositories this
+ /// would be the ".git" folder inside the working directory) or the path to the working directory.
+ /// </param>
+ /// <returns>True if a repository can be resolved through this path; false otherwise</returns>
+ static public bool IsValid(string path)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(path, "path");
+
+ try
+ {
+ Proxy.git_repository_open_ext(path, RepositoryOpenFlags.NoSearch, null);
+ }
+ catch (RepositoryNotFoundException)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
private void EagerlyLoadTheConfigIfAnyPathHaveBeenPassed(RepositoryOptions options)
{
if (options == null)