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 Probes from '../../probes' |
| 2 | import type Types from '../../types' |
| 3 | import { diffDataOf } from '../diff-data-of' |
| 4 | import { withUntracked } from '../with-untracked' |
| 5 | import { EMPTY_NUMSTAT } from './empty-numstat' |
| 6 | |
| 7 | /** |
| 8 | * The one permanent cause of a failed vs-HEAD diff, told apart from the |
| 9 | * passing ones: an unborn HEAD, as the built-in panel tells it apart. |
| 10 | * |
| 11 | * Its rows are the staged files with unstaged edits folded in, then the |
| 12 | * session's untracked files; hunks read against `--cached`, a file edited |
| 13 | * after staging has no honest body; a withheld `--numstat`: no data. |
| 14 | * |
| 15 | * @param context the fetch |
| 16 | * @returns data marked unborn, or unavailable |
| 17 | */ |
| 18 | export async function unbornTier( |
| 19 | context: Types.FetchContext, |
| 20 | ): Promise<Types.FetchOutcome> { |
| 21 | const { run } = context |
| 22 | |
| 23 | if (!(await Probes.isUnbornHead(run))) { |
| 24 | return { kind: 'unavailable' } |
| 25 | } |
| 26 | |
| 27 | const staged = await Probes.statsOf(context, '--cached') |
| 28 | |
| 29 | if (!staged) { |
| 30 | return { kind: 'unavailable' } |
| 31 | } |
| 32 | |
| 33 | const isOverlaid = staged.files.length > 0 |
| 34 | |
| 35 | const unstaged = isOverlaid |
| 36 | ? await Probes.unstagedNumstat(run) |
| 37 | : EMPTY_NUMSTAT |
| 38 | |
| 39 | if (!unstaged) { |
| 40 | return { kind: 'unavailable' } |
| 41 | } |
| 42 | |
| 43 | const merged = await withUntracked( |
| 44 | context, |
| 45 | Probes.overlayUnstaged(staged, unstaged), |
| 46 | 'session-only', |
| 47 | ) |
| 48 | |
| 49 | return { |
| 50 | kind: 'data', |
| 51 | data: diffDataOf(context, merged, { |
| 52 | source: { kind: 'working-tree', base: 'HEAD' }, |
| 53 | baseRef: '--cached', |
| 54 | isUnborn: true, |
| 55 | stalePaths: unstaged.files.map(file => file.path), |
| 56 | }), |
| 57 | } |
| 58 | } |