* Parses a hunk header or throws an error if the given line isn't * a well-formed hunk header. * * We currently only extract the line number information and * ignore any hunk headings. * * Example hunk header (text within ``): * * `@@ -84,10 +82,8 @@ export function parseRawD
(line: string)
| 237 | * Where everything after the last @@ is what's known as the hunk, or section, heading |
| 238 | */ |
| 239 | private parseHunkHeader(line: string): DiffHunkHeader { |
| 240 | const m = diffHeaderRe.exec(line) |
| 241 | if (!m) { |
| 242 | throw new Error(`Invalid hunk header format`) |
| 243 | } |
| 244 | |
| 245 | // If endLines are missing default to 1, see diffHeaderRe docs |
| 246 | const oldStartLine = this.numberFromGroup(m, 1) |
| 247 | const oldLineCount = this.numberFromGroup(m, 2, 1) |
| 248 | const newStartLine = this.numberFromGroup(m, 3) |
| 249 | const newLineCount = this.numberFromGroup(m, 4, 1) |
| 250 | |
| 251 | return new DiffHunkHeader( |
| 252 | oldStartLine, |
| 253 | oldLineCount, |
| 254 | newStartLine, |
| 255 | newLineCount |
| 256 | ) |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Convenience function which lets us leverage the type system to |
no test coverage detected