-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRepositoryLayout.cs
More file actions
40 lines (33 loc) · 1.15 KB
/
Copy pathRepositoryLayout.cs
File metadata and controls
40 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.IO;
namespace Light.GuardClauses.SourceCodeTransformation;
internal static class RepositoryLayout
{
private const string RepositoryMarkerFileName = "Light.GuardClauses.slnx";
public static DirectoryInfo? TryFindRepositoryRoot(IEnumerable<string> searchRoots)
{
var searchedDirectories = new HashSet<string>(StringComparer.Ordinal);
foreach (var searchRoot in searchRoots)
{
if (string.IsNullOrWhiteSpace(searchRoot))
{
continue;
}
var currentDirectory = new DirectoryInfo(Path.GetFullPath(searchRoot));
if (!currentDirectory.Exists)
{
continue;
}
while (currentDirectory != null && searchedDirectories.Add(currentDirectory.FullName))
{
if (File.Exists(Path.Combine(currentDirectory.FullName, RepositoryMarkerFileName)))
{
return currentDirectory;
}
currentDirectory = currentDirectory.Parent;
}
}
return null;
}
}