MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getGitIndexMtime

Function getGitIndexMtime

src/hooks/fileSuggestions.ts:138–147  ·  view source on GitHub ↗

* Stat .git/index to detect git state changes without spawning git ls-files. * Returns null for worktrees (.git is a file → ENOTDIR), fresh repos with no * index yet (ENOENT), and non-git dirs — caller falls back to time throttle.

()

Source from the content-addressed store, hash-verified

136 * index yet (ENOENT), and non-git dirs — caller falls back to time throttle.
137 */
138function getGitIndexMtime(): number | null {
139 const repoRoot = findGitRoot(getCwd())
140 if (!repoRoot) return null
141 try {
142 // eslint-disable-next-line custom-rules/no-sync-fs -- mtimeMs is the operation here, not a pre-check. findGitRoot above already stat-walks synchronously; one more stat is marginal vs spawning git ls-files on every keystroke. Async would force startBackgroundCacheRefresh to become async, breaking the synchronous fileListRefreshPromise contract at the cold-start await site.
143 return statSync(path.join(repoRoot, '.git', 'index')).mtimeMs
144 } catch {
145 return null
146 }
147}
148
149/**
150 * Normalize git paths relative to originalCwd

Callers 1

Calls 2

statSyncFunction · 0.90
getCwdFunction · 0.85

Tested by

no test coverage detected