surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import Argv from './argv' |
| 2 | import { EMPTY_FILE_HUNKS } from './empty-file-hunks' |
| 3 | import GitParse from './parse' |
| 4 | import type Types from './types' |
| 5 | |
| 6 | /** |
| 7 | * One file's hunks against the base its row was read against, so body and |
| 8 | * counts agree, by literal pathspec, as the built-in panel reads hunks. |
| 9 | * |
| 10 | * A rename passes both its paths so git pairs them; an untracked or binary |
| 11 | * row, or on an unborn HEAD a file edited after staging, has no honest |
| 12 | * body and answers no hunks. |
| 13 | * |
| 14 | * @param run runs git against the pinned repository |
| 15 | * @param data the fetch the row belongs to |
| 16 | * @param file the row |
| 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 | } |