(header: string)
| 64 | } |
| 65 | |
| 66 | export function parseDiffGitHeader(header: string): DiffPathPair { |
| 67 | const prefix = "diff --git "; |
| 68 | if (!header.startsWith(prefix)) return {}; |
| 69 | |
| 70 | const rest = header.slice(prefix.length); |
| 71 | if (rest.trimStart().startsWith('"')) { |
| 72 | const first = scanHeaderToken(rest); |
| 73 | const second = first ? scanHeaderToken(first.rest) : null; |
| 74 | if (first && second) { |
| 75 | const oldPath = parsePatchPathToken(first.token, "a"); |
| 76 | const newPath = parsePatchPathToken(second.token, "b"); |
| 77 | return { |
| 78 | oldPath: oldPath && oldPath !== "/dev/null" ? oldPath : undefined, |
| 79 | newPath: newPath && newPath !== "/dev/null" ? newPath : undefined, |
| 80 | }; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | const match = header.match(/^diff --git a\/(.+) b\/(.+)$/); |
| 85 | if (!match) return {}; |
| 86 | return { oldPath: match[1], newPath: match[2] }; |
| 87 | } |
| 88 | |
| 89 | export function formatPatchPathToken(side: "a" | "b", filePath: string): string { |
| 90 | if (filePath === "/dev/null") return filePath; |
no test coverage detected