From 8d8cf0ff11110d3128825617d1a3518563767841 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 1 Jun 2025 07:06:27 +0200 Subject: [PATCH] Refactor file collection logic to ignore .gitignore rules --- main.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 97ab98c..a128261 100644 --- a/main.js +++ b/main.js @@ -1957,17 +1957,28 @@ ipcMain.on('show-tree-context-menu', (event, { absPath, relPath, root, type }) = } // --- Dateien sammeln --- - function getRelevantFiles(dir, maxSize = MAX_TOTAL_SIZE) { + function getGitignoreFilter(folderPath) { + const gitignorePath = path.join(folderPath, '.gitignore'); + if (!fs.existsSync(gitignorePath)) return null; + const content = fs.readFileSync(gitignorePath, 'utf8'); + const ig = ignore().add(content); + return ig; + } + + function getRelevantFiles(dir, maxSize = MAX_TOTAL_SIZE, ig = null, base = null) { + base = base || dir; + if (!ig) ig = getGitignoreFilter(base); let files = []; function walk(current) { for (const f of fs.readdirSync(current)) { const full = path.join(current, f); + const rel = path.relative(base, full); + if (ig && ig.ignores(rel)) continue; if (fs.statSync(full).isDirectory()) { - if (f.startsWith('.')) continue; // .git etc auslassen + if (f.startsWith('.')) continue; walk(full); } else if (isTextFile(full)) { files.push(full); - console.log("pushed " + full) } } }