Skip to content

Commit a2cf84b

Browse files
committed
Don't transcend .git dir to find gitignore files (#531)
1 parent 4aa35f4 commit a2cf84b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/knip/src/util/glob-core.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
77
import { timerify } from './Performance.js';
88
import { compact } from './array.js';
99
import { debugLogObject } from './debug.js';
10-
import { isFile } from './fs.js';
10+
import { isDirectory, isFile } from './fs.js';
1111
import { parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.js';
1212
import { dirname, join, relative, toPosix } from './path.js';
1313

@@ -33,11 +33,13 @@ const cachedGlobIgnores = new Map<string, string[]>();
3333

3434
const findAncestorGitignoreFiles = (cwd: string): string[] => {
3535
const gitignorePaths: string[] = [];
36+
if (isDirectory(join(cwd, '.git'))) return gitignorePaths;
3637
let dir = dirname(cwd);
3738
let prev: string;
3839
while (dir) {
3940
const filePath = join(dir, '.gitignore');
4041
if (isFile(filePath)) gitignorePaths.push(filePath);
42+
if (isDirectory(join(dir, '.git'))) break;
4143
// biome-ignore lint/suspicious/noAssignInExpressions: deal with it
4244
dir = dirname((prev = dir));
4345
if (prev === dir || dir === '.') break;
@@ -124,7 +126,7 @@ export const findAndParseGitignores = async (cwd: string) => {
124126
for (const pattern of ignoresForDir) matchers.add(_picomatch(pattern, pmOptions));
125127
};
126128

127-
findAncestorGitignoreFiles(cwd).forEach(addFile);
129+
for (const filePath of findAncestorGitignoreFiles(cwd)) addFile(filePath);
128130

129131
if (isFile('.git/info/exclude')) addFile('.git/info/exclude', cwd);
130132

0 commit comments

Comments
 (0)