Open sounisi5011 opened 4 years ago
According to .gitignore spec 2.22.1:
The slash / is used as the directory separator. Separators may occur at the beginning, middle or end of the
.gitignore
search pattern.If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular
.gitignore
file itself. Otherwise the pattern may also match at any level below the.gitignore
level.For example, a pattern
doc/frotz/
matchesdoc/frotz
directory, but nota/doc/frotz
directory; howeverfrotz/
matchesfrotz
anda/frotz
that is a directory (all paths are relative from the.gitignore
file).
A patch of code that conforms to this specification is as follows:
const mapGitIgnorePatternTo = base => ignore => {
+ const isSubLevelMatch = /^[^/]+\/?$/.test(ignore);
+
if (ignore.startsWith('!')) {
+ if (isSubLevelMatch) {
+ return '!' + path.posix.join(base, '**', ignore.slice(1));
+ }
return '!' + path.posix.join(base, ignore.slice(1));
}
+ if (isSubLevelMatch) {
+ return path.posix.join(base, '**', ignore);
+ }
return path.posix.join(base, ignore);
};
Is there any progress on this? It's been a year since I reported this bug, and it still doesn't seem to have been fixed. https://github.com/sindresorhus/globby/blob/c1a3b3244ae992ba7e7e76f501a510ea0d9306df/gitignore.js#L18-L24
file structure:
./dir/.gitignore
:List of files to be excluded by git:
If globby works correctly, only the
foo.log
file should be output:However,
globby@11.0.1
outputs like this:The file
dir/subdir/baz.log
is not excluded!When
globby@11.0.1
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,
globby@11.0.1
has changed the contents of the./dir/.gitignore
file to look like this:Therefore, you can avoid this problem by modifying the contents of the
./dir/.gitignore
file as follows: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.