Repository navigation
Fix gitignore ignoring an entire checkout under an anchored ancestor path - #277
Merged
sindresorhus merged 1 commit intoJul 6, 2026
Conversation
…r path
An anchored `.gitignore` pattern like `/foo` is relative to the repository
root, so like git it should only ignore `<repo>/foo`. globby forwards ignore
patterns to fast-glob to skip directories during traversal, expanding directory
patterns to globs along the way. Because `/foo` looks like an absolute path,
that expansion resolved it against the real filesystem: when the checkout lived
under a matching `/foo/…` directory (e.g. a CI runner at `/build/…` or
`/home/…`), `/foo` was a real ancestor directory and expanded to `/foo/**`,
ignoring the whole tree — so `globby(patterns, {gitignore: true, absolute:
true})` returned nothing, diverging from git.
Drop the leading slash when handing anchored patterns to fast-glob so they stay
anchored to the cwd. fast-glob still skips the directory during traversal, and
the cwd-relative predicate keeps enforcing the exact gitignore semantics.
jimmyandrade
added a commit
to itgalaxy/webfont
that referenced
this pull request
Jul 6, 2026
Add a contract test for sindresorhus/globby#277 (anchored ancestor path) and basic resolveInputSources coverage so the Dependabot patch is guarded. Co-authored-by: Cursor <cursoragent@cursor.com>
jimmyandrade
added a commit
to itgalaxy/webfont
that referenced
this pull request
Jul 6, 2026
* chore(deps): bump globby from 16.2.0 to 16.2.1 Bumps [globby](https://github.com/sindresorhus/globby) from 16.2.0 to 16.2.1. - [Release notes](https://github.com/sindresorhus/globby/releases) - [Commits](sindresorhus/globby@v16.2.0...v16.2.1) --- updated-dependencies: - dependency-name: globby dependency-version: 16.2.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * test: document globby 16.2.1 gitignore regression in inputSource Add a contract test for sindresorhus/globby#277 (anchored ancestor path) and basic resolveInputSources coverage so the Dependabot patch is guarded. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jimmy Andrade <contato@jimmyandrade.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #278
Calling globby with
{gitignore: true, absolute: true}returns zero files when the project's absolute path contains a path segment matching an anchored.gitignorepattern (a pattern with a leading/, e.g./build).git check-ignorereports those files as not ignored, so globby diverges from git.Reproduction
The checkout lives under
/tmp, so the anchored/tmp— which git scopes to<repo>/tmponly — is the trigger. (cwdis passed explicitly so the path stays/tmp/...on macOS, wherecd /tmpresolves to/private/tmp.)Cause
An anchored pattern like
/foois relative to the repository root, so git only ignores<repo>/foo. As a traversal optimization, globby forwards.gitignorepatterns to fast-glob'signoreand expands directory patterns to globs. Because/foolooks like an absolute path, that expansion resolves it against the real filesystem — and when the checkout lives under a matching/foo/…directory,/foois a real ancestor directory that expands to/foo/**, which matches every absolute candidate path and prunes the whole tree.Real-world trigger: markdownlint-cli2 globs with
{gitignore: true, absolute: true}; on a CI runner that checks out under/build/…,/home/…or/workspace/…with a matching anchored line, it silently lints 0 files and passes.Fix
Drop the leading slash when handing anchored patterns to fast-glob, so they stay anchored to the cwd instead of the filesystem root. fast-glob still skips the directory during traversal (the optimization is kept), and globby's cwd-relative predicate continues to enforce the exact gitignore semantics. Stripping happens after directory normalization, so
/foo/stays anchored (foo/**) rather than being turned into a recursive**/foo/**. Un-anchored patterns and the negation / git-root short-circuits are unchanged.Test
Adds a regression test (covering
globby,globbySyncandglobbyStreamvia the shared helper) that builds a repo whose leading path segment matches an anchored pattern and asserts only<repo>/<segment>is ignored — not everything, and not a same-named directory nested deeper.