(result: DiffResult)
| 4 | type DiffResult = z.infer<typeof getDiffResponseSchema>; |
| 5 | |
| 6 | export function formatDiffAsGitDiff(result: DiffResult): string { |
| 7 | let output = ''; |
| 8 | |
| 9 | for (const file of result.files) { |
| 10 | output += file.oldPath ? `--- a/${file.oldPath}\n` : `--- /dev/null\n`; |
| 11 | output += file.newPath ? `+++ b/${file.newPath}\n` : `+++ /dev/null\n`; |
| 12 | |
| 13 | for (const hunk of file.hunks) { |
| 14 | const oldStart = hunk.oldRange.start; |
| 15 | const oldLines = hunk.oldRange.lines; |
| 16 | const newStart = hunk.newRange.start; |
| 17 | const newLines = hunk.newRange.lines; |
| 18 | |
| 19 | output += `@@ -${oldStart},${oldLines} +${newStart},${newLines} @@`; |
| 20 | if (hunk.heading) { |
| 21 | output += ` ${hunk.heading}`; |
| 22 | } |
| 23 | output += '\n'; |
| 24 | |
| 25 | output += hunk.body; |
| 26 | if (!hunk.body.endsWith('\n')) { |
| 27 | output += '\n'; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return output; |
| 33 | } |
no outgoing calls
no test coverage detected