From 818f647930c46425e990f55200a6cd7a3f65702c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 14 May 2014 10:06:28 -0700 Subject: [PATCH] Prevent repositories that cannot be cloned from breaking build --- makefile.shade | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/makefile.shade b/makefile.shade index ff30d312d7..0fecdae265 100644 --- a/makefile.shade +++ b/makefile.shade @@ -5,6 +5,7 @@ var VERSION='0.2.1-dev' use namespace='System' use namespace='System.IO' use namespace='System.Collections.Generic' +use namespace='System.Net' use namespace='System.Text.RegularExpressions' use import="BuildEnv" @@ -65,9 +66,25 @@ var repos='${new Dictionary { { GitPull(repo.Value, "dev", repo.Key); } - else + else { - GitClone(repo.Value, "dev"); + if (IsHttpsUrl(repo.Value) && + !IsAccessible(repo.Key)) + { + Log.Warn(string.Format("The repo at '{0}' is not accessible. If you do not have access to this repository, skip the git prompt" + + " for credentials to skip cloning this repository. To avoid this prompt, re-clone the Universe repository over ssh.", + repo.Value)); + } + + try + { + GitClone(repo.Value, "dev"); + } + catch (Exception ex) + { + Log.Warn(string.Format("Unable to clone repository at '{0}'.", repo.Value)); + continue; + } GitConfig("bugtraq.url", "http://github.com/aspnet/" + repo.Key + "/issues/%BUGID%", repo.Key); GitConfig("bugtraq.logregex", @"#(\d+)", repo.Key); } @@ -255,4 +272,25 @@ functions return url.StartsWith("https://", System.StringComparison.OrdinalIgnoreCase); } + + static bool IsAccessible(string key) + { + var req = WebRequest.CreateHttp("https://github.com/aspnet/" + key); + req.Method = "HEAD"; + try + { + using (req.GetResponse()); + } + catch (WebException ex) + { + if (ex.Response != null && + ((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound) + { + return false; + } + + // Ignore any other exception. They should surface as part of git clone with well-known messages. + } + return true; + } }