Skip to content

The pattern in the subdirectory gitignore is not correctly excluded #146

@sounisi5011

Description

@sounisi5011

file structure:

.
├── dir
│   ├── .gitignore
│   ├── bar.log
│   └── subdir
│       └── baz.log
└── foo.log

./dir/.gitignore:

*.log

List of files to be excluded by git:

$ git check-ignore ./foo.log ./dir/bar.log ./dir/subdir/baz.log
./dir/bar.log
./dir/subdir/baz.log

If globby works correctly, only the foo.log file should be output:

const globby = require('globby');

(async () => {
  const paths = await globby(['**/*.log'], { gitignore: true });
  console.log(paths);
  // expected: [ 'foo.log' ]
})();

However, [email protected] outputs like this:

[ 'foo.log', 'dir/subdir/baz.log' ]

The file dir/subdir/baz.log is not excluded!


When [email protected] parses the .gitignore in a subdirectory, it adds the path of the parent to the beginning of each rule:

https://github.com/sindresorhus/globby/blob/v11.0.1/gitignore.js#L18-L24

So, internally, [email protected] has changed the contents of the ./dir/.gitignore file to look like this:

- *.log
+ dir/*.log

Therefore, you can avoid this problem by modifying the contents of the ./dir/.gitignore file as follows:

**/*.log

However, this writing style is redundant. Most projects will probably be written in the *.log style.

I believe this is a bug that should be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions