diff options
author | Arkadiy Shapkin <ashapkin@artec-group.com> | 2013-04-15 01:56:30 +0400 |
---|---|---|
committer | Arkadiy Shapkin <ashapkin@artec-group.com> | 2013-04-17 20:16:57 +0400 |
commit | 98a708ff3433d989415982b7ab824ed2b0f88ab5 (patch) | |
tree | 5a8a99ed59880476d039bcd24df554e85c70bda2 /LibGit2Sharp/Repository.cs | |
parent | 21696b88718ca8b37f68bc6db022a303daf32056 (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.cs | 24 |
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) |