Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions src/core/file/fileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,22 @@ export const getIgnorePatterns = async (rootDir: string, config: RepomixConfigMe
}
}

// Add patterns from .git/info/exclude if useGitignore is enabled
if (config.ignore.useGitignore) {
const excludeFilePath = path.join(rootDir, '.git', 'info', 'exclude');

try {
const excludeFileContent = await fs.readFile(excludeFilePath, 'utf8');
const excludePatterns = parseIgnoreContent(excludeFileContent);

for (const pattern of excludePatterns) {
ignorePatterns.add(pattern);
}
} catch (error) {
// File might not exist or might not be accessible, which is fine
logger.trace('Could not read .git/info/exclude file:', error instanceof Error ? error.message : String(error));
}
}

return Array.from(ignorePatterns);
};
31 changes: 31 additions & 0 deletions tests/core/file/fileSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@ describe('fileSearch', () => {
expect(patterns).toContain('*.custom');
expect(patterns).toContain('temp/');
});

test('should include patterns from .git/info/exclude when useGitignore is true', async () => {
const mockConfig = createMockConfig({
ignore: {
useGitignore: true,
useDefaultPatterns: false,
customPatterns: [],
},
});

const mockExcludeContent = `
# Test exclude file
*.ignored
temp-files/
`;

vi.mocked(fs.readFile).mockImplementation(async (filePath) => {
// Use path.join to create platform-specific path for testing
const excludePath = path.join('.git', 'info', 'exclude');
if (filePath.toString().endsWith(excludePath)) {
return mockExcludeContent;
}
return '';
});

const patterns = await getIgnorePatterns('/mock/root', mockConfig);

// Only test for the exclude file patterns
expect(patterns).toContain('*.ignored');
expect(patterns).toContain('temp-files/');
});
});

describe('parseIgnoreContent', () => {
Expand Down
Loading