fix: Filter noisy git watcher events

Only react to meaningful changes (refs, HEAD, index, objects).
Ignore lock files, FETCH_HEAD, fsmonitor, and other noisy files.
This commit is contained in:
2026-02-14 11:25:16 -06:00
parent 3edc01d713
commit e3ce3712b5

View File

@@ -270,16 +270,42 @@ function broadcastGitChange() {
}
}
// Files to ignore (noisy or irrelevant)
const GIT_IGNORE_PATTERNS = [
'FETCH_HEAD',
'gc.log',
'.lock',
'COMMIT_EDITMSG',
'ORIG_HEAD',
'gitk.cache',
'sourcetreeconfig',
'.DS_Store',
'fsmonitor',
'packed-refs'
]
export function startGitWatcher() {
const gitDir = join(WORKING_DIR, '.git')
try {
// Watch .git directory recursively
gitWatcher = watch(gitDir, { recursive: true }, (eventType, filename) => {
// Ignore some noisy files
if (filename?.includes('FETCH_HEAD') || filename?.includes('gc.log')) {
return
}
if (!filename) return
// Ignore noisy files
const shouldIgnore = GIT_IGNORE_PATTERNS.some(pattern =>
filename.includes(pattern)
)
if (shouldIgnore) return
// Only react to meaningful changes
const isRelevant =
filename.includes('refs/') || // branch/tag changes
filename === 'HEAD' || // checkout
filename === 'index' || // staging area
filename.includes('objects/') // new commits/blobs
if (!isRelevant) return
// Debounce to avoid flooding
if (gitDebounceTimer) {
@@ -287,6 +313,7 @@ export function startGitWatcher() {
}
gitDebounceTimer = setTimeout(() => {
console.log(`[Git] Change: ${filename}`)
broadcastGitChange()
}, GIT_DEBOUNCE_MS)
})