| 159 | } |
| 160 | |
| 161 | function parseAddFileContent(lines: string[], startIdx: number): { content: string; nextIdx: number } { |
| 162 | let content = "" |
| 163 | let i = startIdx |
| 164 | |
| 165 | while (i < lines.length && !lines[i].startsWith("***")) { |
| 166 | if (lines[i].startsWith("+")) { |
| 167 | content += lines[i].substring(1) + "\n" |
| 168 | } |
| 169 | i++ |
| 170 | } |
| 171 | |
| 172 | // Remove trailing newline |
| 173 | if (content.endsWith("\n")) { |
| 174 | content = content.slice(0, -1) |
| 175 | } |
| 176 | |
| 177 | return { content, nextIdx: i } |
| 178 | } |
| 179 | |
| 180 | export function parsePatch(patchText: string): { hunks: Hunk[] } { |
| 181 | const lines = patchText.split("\n") |