If I watch a directory that has a .git inside of it and run fs.watch, does that listen to changes within .git folder?
For example if I use:
fs.watch(dir, { recursive: true }
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
fs.watchjust treats them as regular folders.