public string FindRepo(string dir)
{
var full = System.IO.Path.GetFullPath(dir);
if (string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("GIT_WORKING_DIR")))
{
while (true)
{
if (new DirectoryInfo(Path.Combine(full, ".git")).Exists)
return full;
full = Path.GetDirectoryName(full);
if (Path.GetPathRoot(full) == full)
throw new RepositoryNotFoundException();
}
}
return Directory.GetCurrentDirectory();
}