gitignore.rs icon indicating copy to clipboard operation
gitignore.rs copied to clipboard

Negations seem to 'negate' too much

Open Oliver2213 opened this issue 6 years ago • 0 comments

I'd like to start by saying I'm really new to rust, so apologies in advance if this is something simple that I'm missing. I'm writing a small program to update a set of files by hashing them and comparing against a manifest of hashes. There are other files than the ones in the set in the target directory the program runs in, so I'm using this library to ignore some of them. When I specify a git ignore rule like '*.exe', and then I have a line below that with '!/some-bin.exe', all the other patterns get cleared from the list of ignores. The library I'm using to hash the files takes a BTreeSet of paths to ignore when hashing, so I'm recursing through my target directory with the walkdir library, comparing each path against the vec returned by gitignore::File.included_files, exactly like gitignore::File.is_excluded does, so I end up with a BTreeSet of paths that are excluded. As I stated above, I have a rule that matches all .exe files, and a negation for one specific file a few lines below. When I run my code and have it print out what files are excluded, the only item in the list is the file I wanted to be included :p.

I see this in the documentation for git's gitignore:

An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.

Is this a bug?

Oliver2213 avatar Mar 14 '18 07:03 Oliver2213