1
0

Add .gitignore default entries and skip initial commit check

This commit is contained in:
Victor Giers
2025-11-27 11:45:43 +01:00
parent f38af64e40
commit c508800f83
2 changed files with 51 additions and 21 deletions

35
main.js
View File

@@ -269,15 +269,39 @@ function watchRepo(folder, win) {
repoWatchers.set(folder, watcher);
}*/
function ensureGitignoreDefaults(folderPath) {
const gitignorePath = path.join(folderPath, '.gitignore');
const existing = new Set();
if (fs.existsSync(gitignorePath)) {
fs.readFileSync(gitignorePath, 'utf-8')
.split(/\r?\n/)
.map(l => l.trim())
.filter(Boolean)
.forEach(l => existing.add(l));
}
let changed = false;
for (const entry of MONITOR_DEFAULT_IGNORES) {
if (!existing.has(entry)) {
existing.add(entry);
changed = true;
}
}
if (changed || !fs.existsSync(gitignorePath)) {
fs.writeFileSync(gitignorePath, Array.from(existing).join('\n') + '\n', 'utf-8');
}
}
/**
* Initiiert ein Git-Repo in `folder`, falls noch nicht vorhanden,
* erzeugt bei Bedarf einen leeren Initial-Commit.
* legt ein .gitignore mit Standard-Einträgen an und erstellt einen Initial-Commit.
*/
async function initGitRepo(folder) {
const git = simpleGit(folder);
const gitDir = path.join(folder, '.git');
if (!fs.existsSync(gitDir)) {
await git.init();
ensureGitignoreDefaults(folder);
await git.add(['.gitignore']);
await git.commit('initial commit', undefined, { '--allow-empty': null });
}
}
@@ -751,8 +775,9 @@ function exceedsFileLimit(folderPath, igInstance, limit = 20000) {
return false;
}
function startMonitoringWatcher(folderPath, win) {
function startMonitoringWatcher(folderPath, win, opts = {}) {
if (monitoringWatchers.has(folderPath)) return;
const skipInitialCheck = !!opts.skipInitialCheck;
if (!fs.existsSync(path.join(folderPath, '.git'))) {
debug(`[MONITOR] Überspringe Watcher für ${folderPath}: kein Git-Repo`);
@@ -883,6 +908,7 @@ function startMonitoringWatcher(folderPath, win) {
});
// Initialer Commit (direkt in Queue, wie ein Event)
if (!skipInitialCheck) {
enqueueTask(folderPath, async () => {
debug(`[MONITOR] Starte initialen Commit-Check für ${folderPath}`);
const git = simpleGit(folderPath);
@@ -902,6 +928,9 @@ function startMonitoringWatcher(folderPath, win) {
}
}
});
} else {
debug(`[MONITOR] Überspringe initialen Commit-Check für ${folderPath}`);
}
monitoringWatchers.set(folderPath, watcher);
debug(`[MONITOR] Watcher aktiv für ${folderPath}`);
@@ -2201,7 +2230,7 @@ function buildTrayMenu() {
: f
);
store.set('folders', folders);
startMonitoringWatcher(folderPath, win);
startMonitoringWatcher(folderPath, win, { skipInitialCheck: true });
return { success: true };
} catch (err) {
return { success: false, error: err.message || String(err) };

View File

@@ -500,6 +500,7 @@ window.addEventListener('DOMContentLoaded', async () => {
initRepoBtn.disabled = isGit;
readmeBtn.disabled = !isGit;
pushBtn.disabled = !isGit;
pushBtn.classList.toggle('hidden', !isGit);
if (!isGit) {
contentList.innerHTML = '<div class="p-6 text-gray-500">Not a Git repository. Click "Init Repo" to initialize.</div>';
paginationEl.innerHTML = '';