MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / normalizeFilePath

Function normalizeFilePath

src/utils/commitAttribution.ts:253–292  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

251 * Resolves symlinks to handle /tmp vs /private/tmp on macOS.
252 */
253export function normalizeFilePath(filePath: string): string {
254 const fs = getFsImplementation()
255 const cwd = getAttributionRepoRoot()
256
257 if (!isAbsolute(filePath)) {
258 return filePath
259 }
260
261 // Resolve symlinks in both paths for consistent comparison
262 // (e.g., /tmp -> /private/tmp on macOS)
263 let resolvedPath = filePath
264 let resolvedCwd = cwd
265
266 try {
267 resolvedPath = fs.realpathSync(filePath)
268 } catch {
269 // File may not exist yet, use original path
270 }
271
272 try {
273 resolvedCwd = fs.realpathSync(cwd)
274 } catch {
275 // Keep original cwd
276 }
277
278 if (
279 resolvedPath.startsWith(resolvedCwd + sep) ||
280 resolvedPath === resolvedCwd
281 ) {
282 // Normalize to forward slashes so keys match git diff output on Windows
283 return relative(resolvedCwd, resolvedPath).replaceAll(sep, '/')
284 }
285
286 // Fallback: try original comparison
287 if (filePath.startsWith(cwd + sep) || filePath === cwd) {
288 return relative(cwd, filePath).replaceAll(sep, '/')
289 }
290
291 return filePath
292}
293
294/**
295 * Expand a relative path to absolute path.

Callers 5

getFileMtimeFunction · 0.85
trackFileModificationFunction · 0.85
trackFileDeletionFunction · 0.85
trackBulkFileChangesFunction · 0.85

Calls 2

getFsImplementationFunction · 0.85
getAttributionRepoRootFunction · 0.85

Tested by

no test coverage detected