1
0

auto-git:

[change] main.js
This commit is contained in:
2025-06-01 06:31:21 +02:00
parent 6f098b7906
commit 8cb03fcecf

40
main.js
View File

@@ -466,18 +466,8 @@ async function startMonitoringWatcher(folderPath, win) {
// abfragt als auch das .git-Verzeichnis immer aussperrt. // abfragt als auch das .git-Verzeichnis immer aussperrt.
const watcher = chokidar.watch(folderPath, { const watcher = chokidar.watch(folderPath, {
ignored: (filePath) => { ignored: (filePath) => {
// Immer das .git-Verzeichnis ausschließen // Nur .git ignorieren!
const isInDotGit = /(^|[\/\\])\.git(?:[\/\\]|$)/.test(filePath); return /(^|[\/\\])\.git(?:[\/\\]|$)/.test(filePath);
if (isInDotGit) return true;
// Relativer Pfad zum Repo
const rel = path.relative(folderPath, filePath);
if (!rel || rel === '' || rel === '.') return true;
// 1) Wenn die Datei in der .gitignore steht → ignorieren
if (igFilter.ignores(rel)) return true;
// 2) Ansonsten wird die Änderung durch unseren Code ohnehin
// beim Commit-Check berücksichtigt (wir ignorieren nur, was auch wirklich in IGNORED_NAMES ist).
return false;
}, },
ignoreInitial: true, ignoreInitial: true,
persistent: true, persistent: true,
@@ -497,17 +487,14 @@ async function startMonitoringWatcher(folderPath, win) {
const rel = path.relative(folderPath, filePathAbsolute); const rel = path.relative(folderPath, filePathAbsolute);
if (!rel || rel === '' || rel === '.') return; if (!rel || rel === '' || rel === '.') return;
// a) Prüfe, ob dieser Pfad durch die aktuell geladene .gitignore // Ab hier wie gehabt:
// bereits ausgeschlossen ist (z.B. node_modules/foo.js): // - Prüfe erst, ob bereits in .gitignore
if (igFilter.ignores(rel)) { if (igFilter.ignores(rel)) {
// Falls wir bisher noch nicht in .gitignore hatten, dort hinzufügen: // Falls nicht schon in .gitignore, hinzufügen
// (Aber eigentlich sollte .gitignore aktuell sein, weil doAutoCommitWithIgnoreCheck()
// ja erst dafür gesorgt hat.)
const parts = rel.split(path.sep); const parts = rel.split(path.sep);
const entry = parts.length > 1 ? parts[0] + '/' : rel; const entry = parts.length > 1 ? parts[0] + '/' : rel;
const didWrite = await ensureIgnoredInGitignore(folderPath, entry); const didWrite = await ensureIgnoredInGitignore(folderPath, entry);
if (didWrite) { if (didWrite) {
// Neue .gitignore-Muster einladen
igFilter = await loadGitignoreFilter(folderPath); igFilter = await loadGitignoreFilter(folderPath);
await git.add('.gitignore'); await git.add('.gitignore');
await git.commit('auto-git: Hinzufügen zu .gitignore'); await git.commit('auto-git: Hinzufügen zu .gitignore');
@@ -517,7 +504,22 @@ async function startMonitoringWatcher(folderPath, win) {
return; return;
} }
// b) Ansonsten ganz normal alle Änderungen committen // Dann: Prüfe, ob nach IGNORED_NAMES ignorieren (→ zur .gitignore hinzufügen)
if (isIgnoredByList(rel)) {
const parts = rel.split(path.sep);
const entry = parts.length > 1 ? parts[0] + '/' : rel;
const didWrite = await ensureIgnoredInGitignore(folderPath, entry);
if (didWrite) {
igFilter = await loadGitignoreFilter(folderPath);
await git.add('.gitignore');
await git.commit('auto-git: Hinzufügen zu .gitignore');
win.webContents.send('repo-updated', folderPath);
debug(`[WATCHER] "${entry}" aus IGNORED_NAMES zu .gitignore hinzugefügt und committed`);
}
return;
}
// ... Normal weiter committen
await doAutoCommitWithIgnoreCheck(); await doAutoCommitWithIgnoreCheck();
}); });