From 82b4dbefa13949dd50fd66cae3f0563c55bd4efe Mon Sep 17 00:00:00 2001 From: Cory Todd Date: Thu, 25 Apr 2024 19:24:38 -0700 Subject: [PATCH] fix: ignore paths normalization It is not correct to generate absolute paths. Instead, resolve the path then use the Path library to compare absolute paths as needed. --- Walrus.Core.Tests/MockRepoProvider.cs | 12 ++++++++++++ Walrus.Core/PathHelper.cs | 21 ++++++--------------- samples/walrus.json | 13 ++++++++----- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Walrus.Core.Tests/MockRepoProvider.cs b/Walrus.Core.Tests/MockRepoProvider.cs index 971301c..78af6d0 100644 --- a/Walrus.Core.Tests/MockRepoProvider.cs +++ b/Walrus.Core.Tests/MockRepoProvider.cs @@ -1,5 +1,6 @@ namespace Walrus.Core.Tests { + using System; using System.Collections.Generic; using Repository; @@ -93,5 +94,16 @@ public IEnumerable GetRepositories(string rootDirectory, int s }) }; } + + public IEnumerable GetRepositories(string rootDirectory, int scanDepth, bool allBranches, Predicate excludeFilter = null) + { + foreach(var repo in GetRepositories(rootDirectory, scanDepth, allBranches)) + { + if (!excludeFilter(repo.RepositoryPath)) + { + yield return repo; + } + } + } } } \ No newline at end of file diff --git a/Walrus.Core/PathHelper.cs b/Walrus.Core/PathHelper.cs index 7163885..2236397 100644 --- a/Walrus.Core/PathHelper.cs +++ b/Walrus.Core/PathHelper.cs @@ -16,8 +16,8 @@ public static class PathHelper /// Automatically resolve all environmental variables and /// the home tilda (~/) in path. /// - /// Path to resovle - /// Resolved path + /// Path to resolve + /// Absolute resolved path public static string ResolvePath(string path) { ArgumentNullException.ThrowIfNull(path); @@ -29,22 +29,13 @@ public static string ResolvePath(string path) } path = ResolveAllEnvironmentVariables(path); - path = Normalize(path); return path; } - internal static string Normalize(string path) - { - return Path.GetFullPath(path) - .Trim() - .TrimEnd(Path.DirectorySeparatorChar); - } - /// /// Returns true if contains . - /// All paths are normalized beforce testing. /// /// List of paths to test against /// @@ -52,13 +43,13 @@ internal static string Normalize(string path) internal static bool ContainsPath(IList pathList, string repositoryPath) { var found = false; - var normalizedTarget = Normalize(repositoryPath); + var normalizedPath = Path.GetFullPath(ResolvePath(repositoryPath)); foreach(var ignoredRepo in pathList) { - var normalizedIgnore = Normalize(ignoredRepo); - found = normalizedTarget == normalizedIgnore; - if(found) + var normalizedIgnoredRepo = Path.GetFullPath(ResolvePath(ignoredRepo)); + if (normalizedIgnoredRepo == normalizedPath) { + found = true; break; } } diff --git a/samples/walrus.json b/samples/walrus.json index 8c27f13..a515c89 100644 --- a/samples/walrus.json +++ b/samples/walrus.json @@ -4,9 +4,12 @@ "H:\\code" ], "AuthorAliases": { - "illyum": [ - "illy@home.com", - "illy@work.com" - ] - } + "illyum": [ + "illy@home.com", + "illy@work.com" + ] + }, + "IgnorePaths": [ + "H:\\code\\llvm" + ] }