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 { branchSourceOf } from './branch-source-of' |
| 4 | import { diffDataOf } from './diff-data-of' |
| 5 | import { unbornTier } from './unborn-tier' |
| 6 | import { withUntracked } from './with-untracked' |
| 7 | |
| 8 | /** |
| 9 | * Branch mode: everything that differs from the default branch, the merge |
| 10 | * base against the working tree, pinned, as the built-in panel diffs it. |
| 11 | * |
| 12 | * With HEAD at the base the diff is HEAD's under the vs-<default> label; |
| 13 | * with no base it is labelled a plain working-tree diff; a base that may |
| 14 | * resolve next time answers unavailable so the last branch view stays. |
| 15 | * |
| 16 | * @param context the fetch |
| 17 | * @returns the outcome |
| 18 | */ |
| 19 | export async function branchTier( |
| 20 | context: Types.FetchContext, |
| 21 | ): Promise<Types.FetchOutcome> { |
| 22 | const { deps, run } = context |
| 23 | const base = await Probes.branchBaseOf(run) |
| 24 | deps.onBranchBase(base) |
| 25 | |
| 26 | if (base.kind === 'error') { |
| 27 | return unbornTier(context) |
| 28 | } |
| 29 | |
| 30 | const source = branchSourceOf(base) |
| 31 | const baseRef = source.kind === 'branch' ? source.baseRef : 'HEAD' |
| 32 | const diff = await Probes.statsOf(context, baseRef) |
| 33 | const isTransientFailure = diff === null && base.kind === 'merge-base' |
| 34 | |
| 35 | if (isTransientFailure) { |
| 36 | return { kind: 'unavailable' } |
| 37 | } |
| 38 | |
| 39 | if (!diff) { |
| 40 | return unbornTier(context) |
| 41 | } |
| 42 | |
| 43 | return { |
| 44 | kind: 'data', |
| 45 | data: diffDataOf( |
| 46 | context, |
| 47 | await withUntracked(context, diff, 'session-only'), |
| 48 | { |
| 49 | source, |
| 50 | baseRef, |
| 51 | isUnborn: false, |
| 52 | stalePaths: [], |
| 53 | }, |
| 54 | ), |
| 55 | } |
| 56 | } |