Skip to content
Snippets Groups Projects
Commit e063042f authored by Stanley Goldman's avatar Stanley Goldman
Browse files

Making Utility.FindCommonPath() look for the common parent directory

parent d19af328
No related branches found
No related tags found
No related merge requests found
......@@ -99,12 +99,12 @@ namespace GitHub.Unity
// Based on: https://www.rosettacode.org/wiki/Find_common_directory_path#C.23
public static string FindCommonPath(IEnumerable<string> paths)
{
var longestPath =
paths.First(first => first.Length == paths.Max(second => second.Length))
.ToNPath();
var pathsArray = paths.Select(s => s.ToNPath().Parent).ToArray();
var maxDepth = pathsArray.Max(path => path.Depth);
var deepestPath = pathsArray.First(path => path.Depth == maxDepth);
NPath commonParent = longestPath;
foreach (var path in paths)
var commonParent = deepestPath;
foreach (var path in pathsArray)
{
var cp = commonParent.GetCommonParent(path);
if (cp != null)
......
......@@ -152,8 +152,7 @@ namespace GitHub.Unity
// Build tree structure
var commonParentDirectory = Utility.FindCommonPath(entries.Select(e => e.Path.ToNPath().Parent.ToString()));
tree = new FileTreeNode(commonParentDirectory);
tree = new FileTreeNode(Utility.FindCommonPath(entries.Select(e => e.Path)));
tree.RepositoryPath = tree.Path;
for (var index = 0; index < entries.Count; index++)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment