79816593

Date: 2025-11-11 11:49:14
Score: 0.5
Natty:
Report link

Yes fs watch listens to hidden folders.

I was running custom logic in a file system watcher with recursive: true. Since my watcher also observed the .git folder, running Git commands inside the watcher created a feedback loop: the Git commands modified the .git folder, which triggered the watcher again, and so on.

Fix: Ignore changes in the .git folder:

const watcher = fs.watch(dir, { recursive: true }, (eventType, filename) => {
  if (filename && (filename.startsWith(".git") || filename.includes(`${path.sep}.git`))) {
    console.log("Git folder changed, ignoring...");
    return;
  }

  throttledNotify();
});

Somewhere in throttledNotify i was running const stdout = await runGitCommand(["status", "--porcelain"], dir); which causes the infinite feedback loop

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Yousaf Wazir