Skip to content

Commit

Permalink
fix: ignore paths normalization
Browse files Browse the repository at this point in the history
It is not correct to generate absolute paths. Instead, resolve the path
then use the Path library to compare absolute paths as needed.
  • Loading branch information
corytodd committed Apr 26, 2024
1 parent 4dbd418 commit 82b4dbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
12 changes: 12 additions & 0 deletions Walrus.Core.Tests/MockRepoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Walrus.Core.Tests
{
using System;
using System.Collections.Generic;
using Repository;

Expand Down Expand Up @@ -93,5 +94,16 @@ public IEnumerable<WalrusRepository> GetRepositories(string rootDirectory, int s
})
};
}

public IEnumerable<WalrusRepository> GetRepositories(string rootDirectory, int scanDepth, bool allBranches, Predicate<string> excludeFilter = null)
{
foreach(var repo in GetRepositories(rootDirectory, scanDepth, allBranches))
{
if (!excludeFilter(repo.RepositoryPath))
{
yield return repo;
}
}
}
}
}
21 changes: 6 additions & 15 deletions Walrus.Core/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static class PathHelper
/// Automatically resolve all environmental variables and
/// the home tilda (~/) in path.
/// </summary>
/// <param name="path">Path to resovle</param>
/// <return>Resolved path</return>
/// <param name="path">Path to resolve</param>
/// <return>Absolute resolved path</return>
public static string ResolvePath(string path)
{
ArgumentNullException.ThrowIfNull(path);
Expand All @@ -29,36 +29,27 @@ 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);
}

/// <summary>
/// Returns true if <paramref name="pathList"/> contains <paramref name="repositoryPath"/>.
/// All paths are normalized beforce testing.
/// </summary>
/// <param name="ignoredRepos">List of paths to test against</param>
/// <param name="repositoryPath"></param>
/// <returns></returns>
internal static bool ContainsPath(IList<string> 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;
}
}
Expand Down
13 changes: 8 additions & 5 deletions samples/walrus.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"H:\\code"
],
"AuthorAliases": {
"illyum": [
"[email protected]",
"[email protected]"
]
}
"illyum": [
"[email protected]",
"[email protected]"
]
},
"IgnorePaths": [
"H:\\code\\llvm"
]
}

0 comments on commit 82b4dbe

Please sign in to comment.