(oldContent: string, newContent: string)
| 484 | } |
| 485 | |
| 486 | function generateUnifiedDiff(oldContent: string, newContent: string): string { |
| 487 | const oldLines = oldContent.split("\n") |
| 488 | const newLines = newContent.split("\n") |
| 489 | |
| 490 | // Simple diff generation - in a real implementation you'd use a proper diff algorithm |
| 491 | let diff = "@@ -1 +1 @@\n" |
| 492 | |
| 493 | // Find changes (simplified approach) |
| 494 | const maxLen = Math.max(oldLines.length, newLines.length) |
| 495 | let hasChanges = false |
| 496 | |
| 497 | for (let i = 0; i < maxLen; i++) { |
| 498 | const oldLine = oldLines[i] || "" |
| 499 | const newLine = newLines[i] || "" |
| 500 | |
| 501 | if (oldLine !== newLine) { |
| 502 | if (oldLine) diff += `-${oldLine}\n` |
| 503 | if (newLine) diff += `+${newLine}\n` |
| 504 | hasChanges = true |
| 505 | } else if (oldLine) { |
| 506 | diff += ` ${oldLine}\n` |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return hasChanges ? diff : "" |
| 511 | } |
| 512 | |
| 513 | // Apply hunks to filesystem |
| 514 | export const applyHunksToFiles = Effect.fn("Patch.applyHunksToFiles")(function* (hunks: Hunk[]) { |
no outgoing calls
no test coverage detected