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:
@@ -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() {
|
export function startGitWatcher() {
|
||||||
const gitDir = join(WORKING_DIR, '.git')
|
const gitDir = join(WORKING_DIR, '.git')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Watch .git directory recursively
|
// Watch .git directory recursively
|
||||||
gitWatcher = watch(gitDir, { recursive: true }, (eventType, filename) => {
|
gitWatcher = watch(gitDir, { recursive: true }, (eventType, filename) => {
|
||||||
// Ignore some noisy files
|
if (!filename) return
|
||||||
if (filename?.includes('FETCH_HEAD') || filename?.includes('gc.log')) {
|
|
||||||
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
|
// Debounce to avoid flooding
|
||||||
if (gitDebounceTimer) {
|
if (gitDebounceTimer) {
|
||||||
@@ -287,6 +313,7 @@ export function startGitWatcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gitDebounceTimer = setTimeout(() => {
|
gitDebounceTimer = setTimeout(() => {
|
||||||
|
console.log(`[Git] Change: ${filename}`)
|
||||||
broadcastGitChange()
|
broadcastGitChange()
|
||||||
}, GIT_DEBOUNCE_MS)
|
}, GIT_DEBOUNCE_MS)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user