Skip to content

fix: consecutive leading **/ should match like a single **/ - #161

Merged
kaelzhang merged 1 commit into
kaelzhang:masterfrom
spokodev:fix/consecutive-leading-globstar
Jul 10, 2026
Merged

fix: consecutive leading **/ should match like a single **/#161
kaelzhang merged 1 commit into
kaelzhang:masterfrom
spokodev:fix/consecutive-leading-globstar

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

A pattern with consecutive leading globstars such as **/**/foo fails to match foo at the repository root, while git check-ignore matches it.

ignore().add('**/**/foo').ignores('foo')      // false, should be true
ignore().add('**/**/foo').ignores('a/foo')    // true (correct)
$ printf '**/**/foo\n' > .gitignore
$ git check-ignore --no-index foo
foo

Only the root case is wrong; a/foo and a/b/foo already match. Git treats a run of leading **/ the same as a single **/ ("match in all directories", including zero), so **/**/foo is equivalent to **/foo.

Cause: the leading-globstar replacer only consumes the first **/. The remaining **/ is then handled as an ordinary **, which forces at least one intermediate directory and drops the root match.

Fix: let the replacer consume one or more consecutive leading **/ runs. **/**/foo now compiles to the same regex as **/foo.

Adds a regression test to test/fixtures/cases.js (exercised by .ignores(), .filter(), .checkIgnore() and the git check-ignore fixture oracle).

@kaelzhang
kaelzhang merged commit 424a2bb into kaelzhang:master Jul 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants