Skip to content

Commit

Permalink
FilterPath: Recurse into child directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik authored and AArnott committed May 29, 2021
1 parent 460ed85 commit e987a7e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/NerdBank.GitVersioning/FilterPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,31 @@ public bool Includes(string repoRelativePath, bool ignoreCase)
stringComparison);
}

/// <summary>
/// Determines if children of <paramref name="repoRelativePath"/> may be included
/// by this <see cref="FilterPath"/>.
/// </summary>
/// <param name="repoRelativePath">Forward-slash delimited path (repo relative).</param>
/// <param name="ignoreCase">
/// Whether paths should be compared case insensitively.
/// Should be the 'core.ignorecase' config value for the repository.
/// </param>
/// <returns>
/// <see langword="true"/> if this <see cref="FilterPath"/> is an including filter that may match
/// children of <paramref name="repoRelativePath"/>, otherwise <see langword="false"/>.
/// </returns>
public bool IncludesChildren(string repoRelativePath, bool ignoreCase)
{
if (repoRelativePath is null)
throw new ArgumentNullException(nameof(repoRelativePath));

if (!this.IsInclude) return false;
if (this.IsRoot) return true;

var stringComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
return this.RepoRelativePath.StartsWith(repoRelativePath + "/", stringComparison);
}

private static (int dirsToAscend, StringBuilder result) GetRelativePath(string path, string relativeTo)
{
var pathParts = path.Split('/');
Expand Down

0 comments on commit e987a7e

Please sign in to comment.