Pattern matching is too greedy
var parser = require('gitignore-parser').compile('package');
parser.accepts('package.json'); // false
I would think that package.json should still be accepted since git CLI would not ignore that file with that .gitignore.
I found the same thing. This logic is incorrect:
accepts: function (input) {
if (input[0] === '/') input = input.slice(1);
return negatives[0].test(input) || !positives[0].test(input);
},
It should be something like (but write tests to verify since I only tested my use case):
accepts: function (input) {
if (input[0] === '/') input = input.slice(1);
if (positives[0].test(input)) return false;
return negatives[0].test(input));
},
I found it through doing something like and testing node_modules/backbone/package.json:
node_modules/
!node_modules/backbone/*
This library will list things in the backbone directory, but git would ignore the files based on the first condition before getting to the second one.
I tried to port gitignore tests from libgit2 to to this module and stopped. The problem is that actually implementing gitignore to be fully compliant is very complex.
I've moved over to using the following module: https://github.com/kaelzhang/node-ignore