shouldAddPath function

bool shouldAddPath(
  1. String path, {
  2. String pattern = star,
})

path starts with Platform.pathSeparator as a relative path from the Repositoryparent dir

Implementation

bool shouldAddPath(String path, {String pattern = star}) {
  debugPrintToConsole(message: "Checking if should add Path: $path", newLine: true);
  debugPrintToConsole(message: "Pattern: $pattern");

  if (pattern == dot || pattern == star || pattern.isEmpty) return true;

  final IgnorePatternRules rule = IgnorePatternRules.detectRule(pattern);
  final bool matched = switch (rule) {
    IgnorePatternRules.pathFromRoot => rule.patternMatches(
      testPattern: pattern,
      inputPattern: path,
    ),
    IgnorePatternRules.suffix => rule.patternMatches(
      testPattern: pattern,
      inputPattern: path,
    ),
    IgnorePatternRules.single => rule.patternMatches(
      testPattern: pattern,
      inputPattern: stripBeginningPathSeparatorPath(path),
    ),
    IgnorePatternRules.contains => rule.patternMatches(
      testPattern: pattern,
      inputPattern: path,
    ),
    IgnorePatternRules.exactMatch => rule.patternMatches(
      testPattern: pattern,
      inputPattern: stripBeginningPathSeparatorPath(path),
    ),
  };

  debugPrintToConsole(message: "Result: $matched");
  debugPrintToConsole(message: "Description: Pattern matched $matched against $rule");

  return matched;
}