Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/rstack/src/fmt/discoverPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ class GitIgnoreMatcher {
}

#matches(relativePath: string, isDirectory: boolean): boolean {
// Most repositories only use a root `.gitignore`. Avoid checking every path
// segment when no nested matcher can override its result.
const rootMatcher = this.#matchers.size === 1 ? this.#matchers.get(this.#rootPath) : undefined;
if (rootMatcher) {
// `ignore` expects POSIX separators and uses a trailing slash to distinguish directories.
const pathFromMatcher = toPosixPath(relativePath);
return rootMatcher.test(isDirectory ? `${pathFromMatcher}/` : pathFromMatcher).ignored;
}

const segments = relativePath.split(path.sep);
let directoryPath = this.#rootPath;
let pathFromMatcher = segments.join('/');
Expand Down