spacehub

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

claude-code / mods / diff / hooks / git / fetch-diff.ts
33 lines · 952 BRaw
1import Probes from './probes'
2import Tiers from './tiers'
3import type Types from './types'
4
5/**
6 * One fetch of the session's pinned repository, as the built-in panel
7 * fetches; every git child names it so paths stay root-relative.
8 *
9 * Mid-merge, mid-rebase, mid-cherry-pick or mid-revert, or when git cannot
10 * answer, it is unavailable and the caller keeps what it had.
11 *
12 * @param deps the host: pinned git, the repository, the file probes
13 * @param mode what to compare against
14 * @returns the outcome
15 */
16export async function fetchDiff(
17 deps: Types.GitDeps,
18 mode: Types.BaseMode,
19): Promise<Types.FetchOutcome> {
20 const isBusy = await Probes.isTransient(
21 deps.entryKindsOf,
22 deps.repository.gitDir,
23 )
24
25 if (isBusy) {
26 return { kind: 'unavailable' }
27 }
28
29 const context = Tiers.fetchContextOf(deps, mode)
30 const isBranch = mode === 'branch'
31
32 return isBranch ? Tiers.branchTier(context) : Tiers.workingTreeTier(context)
33}