ignore
ignore copied to clipboard
Differentiate between no match and a negated match
Thanks for the awesome library, I've been using this for years! I'm using Ignore with .gitignore files that I load into it, and I need my code to support nested .gitignore files (e.g. repo/.gitignore
and repo/src/.gitignore
. There's a way this library could make it easy to support this use case with relatively minor edits. (I know that full nested support is considered out of scope https://github.com/goelhardik/ignore/issues/26#issuecomment-800498582, I also would like to avoid using libgit2sharp)
repo/.gitignore
:
*.wasm
repo/src/.gitignore
:
!*.wasm
Here's my code:
var ignoresForThisPath = [LoadIgnore("repo/src/.gitignore"), LoadIgnore("repo/.gitignore")];
for(var i = ignoresForThisPath.Count - 1; i >= 0; i--)
{
var ignore = ignoresForThisPath[i].Ignore;
var folder = ignoresForThisPath[i].Folder;
var relativePath = Path.GetRelativePath(folder.FullName, path.FullName)
.Replace("\\", "/");
if (ignore.IsIgnored(relativePath) || ignore.IsIgnored(relativePath + "/"))
{
return true;
}
}
The problem is, the first ignore, which has the negated pattern (!*.wasm
) says, the path is not ignored. But I have no way of short-circuiting the checks for parent / ancestor directories. I want to short-circuit the checks because the path is explicitly not ignored. Is there a way we can return an enum from IsIgnored that has values like EXPLICITLY_IGNORED
, EXPLICITLY_NOT_IGNORED
and NO_RULES_APPLY
where NO_RULES_APPLY
and EXPLICITLY_NOT_IGNORED
would both correspond to the current return value of true
? This is a smaller scope than nested ignores, should this be in scope or out do you think?