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

Function generateSyntheticDiff

src/utils/gitDiff.ts:504–532  ·  view source on GitHub ↗
(
  gitPath: string,
  absoluteFilePath: string,
)

Source from the content-addressed store, hash-verified

502}
503
504async function generateSyntheticDiff(
505 gitPath: string,
506 absoluteFilePath: string,
507): Promise<Omit<ToolUseDiff, 'repository'> | null> {
508 try {
509 if (!isFileWithinReadSizeLimit(absoluteFilePath, MAX_DIFF_SIZE_BYTES)) {
510 return null
511 }
512 const content = await readFile(absoluteFilePath, 'utf-8')
513 const lines = content.split('\n')
514 // Remove trailing empty line from split if file ends with newline
515 if (lines.length > 0 && lines.at(-1) === '') {
516 lines.pop()
517 }
518 const lineCount = lines.length
519 const addedLines = lines.map(line => `+${line}`).join('\n')
520 const patch = `@@ -0,0 +1,${lineCount} @@\n${addedLines}`
521 return {
522 filename: gitPath,
523 status: 'added',
524 additions: lineCount,
525 deletions: 0,
526 changes: lineCount,
527 patch,
528 }
529 } catch {
530 return null
531 }
532}

Callers 1

fetchSingleFileGitDiffFunction · 0.85

Calls 2

readFileFunction · 0.85

Tested by

no test coverage detected