* Parse git diff --raw -z output * * Format for normal operations (M, A, D): * :oldmode newmode oldsha newsha status\0path\0 * * Format for renames/copies (R, C): * :oldmode newmode oldsha newsha status\0oldpath\0newpath\0 * * Note: Rename/Copy status includes similarity (e.g., R100, R90
(rawOutput: string)
| 57 | * Note: Rename/Copy status includes similarity (e.g., R100, R90, C100) |
| 58 | */ |
| 59 | function parseRawDiff(rawOutput: string): RawDiffEntry[] { |
| 60 | const entries = rawOutput.split('\0').filter(Boolean); |
| 61 | const results: RawDiffEntry[] = []; |
| 62 | |
| 63 | let i = 0; |
| 64 | while (i < entries.length) { |
| 65 | const metaLine = entries[i]; |
| 66 | i++; |
| 67 | |
| 68 | if (!metaLine || i >= entries.length) { |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | // Parse: :100644 100644 abc123... def456... M (or R100, C100, etc) |
| 73 | const parts = metaLine.trim().split(/\s+/); |
| 74 | if (parts.length < 5) { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | const shaA = parts[2] === '0000000000000000000000000000000000000000' ? null : parts[2]; |
| 79 | const shaB = parts[3] === '0000000000000000000000000000000000000000' ? null : parts[3]; |
| 80 | const status = parts[4]; |
| 81 | |
| 82 | // Check if this is a rename or copy operation |
| 83 | // Status will be like: R100, R90, C100, C95, etc. |
| 84 | const isRenameOrCopy = status.startsWith('R') || status.startsWith('C'); |
| 85 | |
| 86 | if (isRenameOrCopy) { |
| 87 | // Renames and copies have TWO paths: oldpath and newpath |
| 88 | // Format: metadata\0oldpath\0newpath\0 |
| 89 | const oldPath = entries[i]; |
| 90 | i++; |
| 91 | const newPath = entries[i]; |
| 92 | i++; |
| 93 | |
| 94 | if (!oldPath || !newPath) { |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | // Use the new/destination path as the main path |
| 99 | results.push({ path: newPath, oldPath, status, shaA, shaB }); |
| 100 | } else { |
| 101 | // Normal operations (M, A, D) have ONE path |
| 102 | // Format: metadata\0path\0 |
| 103 | const filePath = entries[i]; |
| 104 | i++; |
| 105 | |
| 106 | if (!filePath) { |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | results.push({ path: filePath, status, shaA, shaB }); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return results; |
| 115 | } |
| 116 |
no test coverage detected
searching dependent graphs…