MCPcopy Create free account
hub / github.com/arctic-cli/interface / generateUnifiedDiff

Function generateUnifiedDiff

packages/arctic/src/patch/index.ts:432–457  ·  view source on GitHub ↗
(oldContent: string, newContent: string)

Source from the content-addressed store, hash-verified

430 }
431
432 function generateUnifiedDiff(oldContent: string, newContent: string): string {
433 const oldLines = oldContent.split("\n")
434 const newLines = newContent.split("\n")
435
436 // Simple diff generation - in a real implementation you'd use a proper diff algorithm
437 let diff = "@@ -1 +1 @@\n"
438
439 // Find changes (simplified approach)
440 const maxLen = Math.max(oldLines.length, newLines.length)
441 let hasChanges = false
442
443 for (let i = 0; i < maxLen; i++) {
444 const oldLine = oldLines[i] || ""
445 const newLine = newLines[i] || ""
446
447 if (oldLine !== newLine) {
448 if (oldLine) diff += `-${oldLine}\n`
449 if (newLine) diff += `+${newLine}\n`
450 hasChanges = true
451 } else if (oldLine) {
452 diff += ` ${oldLine}\n`
453 }
454 }
455
456 return hasChanges ? diff : ""
457 }
458
459 // Apply hunks to filesystem
460 export async function applyHunksToFiles(hunks: Hunk[]): Promise<AffectedPaths> {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected