Fail gracefully when repositories have cycles

Fixes #451
This commit is contained in:
Pranav K 2016-08-26 10:19:21 -07:00 committed by GitHub
parent 3bf98d2b34
commit aa97e4d777
1 changed files with 22 additions and 6 deletions

View File

@ -929,15 +929,31 @@ functions
{
get
{
if (Dependencies.Count > 0)
{
return 1 + Dependencies.Max(d => d.Order);
}
return 1;
return GetOrder(new List<RepositoryInfo>(), this);
}
}
private static int GetOrder(List<RepositoryInfo> visited, RepositoryInfo info)
{
if (visited.Contains(info))
{
throw new Exception("A cyclic dependency between the following repositories has been detected: " +
string.Join(" -> ", visited));
}
visited.Add(info);
var order = 0;
foreach (var dependency in info.Dependencies)
{
order = Math.Max(order, GetOrder(visited, dependency));
}
visited.RemoveAt(visited.Count - 1);
return order + 1;
}
public override string ToString()
{
return Name;