( numstatOutput: string, )
| 120 | } |
| 121 | |
| 122 | export function parseDiffNumstat( |
| 123 | numstatOutput: string, |
| 124 | ): Map<string, { additions: number; deletions: number }> { |
| 125 | const stats = new Map<string, { additions: number; deletions: number }>(); |
| 126 | |
| 127 | for (const line of numstatOutput.trim().split("\n")) { |
| 128 | if (!line.trim()) continue; |
| 129 | |
| 130 | // Format: additions\tdeletions\tfilepath |
| 131 | // For renames: additions\tdeletions\toldpath => newpath |
| 132 | const [addStr, delStr, ...pathParts] = line.split("\t"); |
| 133 | const rawPath = pathParts.join("\t"); |
| 134 | if (!rawPath) continue; |
| 135 | |
| 136 | const additions = addStr === "-" ? 0 : Number.parseInt(addStr, 10) || 0; |
| 137 | const deletions = delStr === "-" ? 0 : Number.parseInt(delStr, 10) || 0; |
| 138 | const statEntry = { additions, deletions }; |
| 139 | |
| 140 | const renameMatch = rawPath.match(/^(.+) => (.+)$/); |
| 141 | if (renameMatch) { |
| 142 | const oldPath = renameMatch[1]; |
| 143 | const newPath = renameMatch[2]; |
| 144 | stats.set(newPath, statEntry); |
| 145 | stats.set(oldPath, statEntry); |
| 146 | } else { |
| 147 | stats.set(rawPath, statEntry); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return stats; |
| 152 | } |
| 153 | |
| 154 | export function parseNameStatus(nameStatusOutput: string): ChangedFile[] { |
| 155 | const files: ChangedFile[] = []; |
no test coverage detected