| 17 | * @returns the parsed body, or null when git failed |
| 18 | */ |
| 19 | export async function fetchFileHunks( |
| 20 | run: Types.GitRun, |
| 21 | data: Types.DiffData, |
| 22 | file: Types.FileStat, |
| 23 | ): Promise<Types.FileHunks | null> { |
| 24 | const hasNoBody = |
| 25 | file.isUntracked || file.isBinary || data.stalePaths.includes(file.path) |
| 26 | |
| 27 | if (hasNoBody) { |
| 28 | return EMPTY_FILE_HUNKS |
| 29 | } |
| 30 | |
| 31 | const { exitCode, stdout } = await run([ |
| 32 | '--literal-pathspecs', |
| 33 | ...Argv.DIFF_LEADING_ARGS, |
| 34 | data.baseRef, |
| 35 | '--', |
| 36 | ...(file.renamedFrom === null ? [] : [file.renamedFrom]), |
| 37 | file.path, |
| 38 | ]) |
| 39 | |
| 40 | return exitCode === 0 ? GitParse.parseFileDiff(stdout) : null |
| 41 | } |