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 / pane-state / base-label-of.ts
46 lines · 1.3 KBRaw
1import type Backend from '../backend'
2import type Git from '../git'
3import { modeLabelOf } from './mode-label-of'
4
5/**
6 * The dim line under the header naming what the diff compares against
7 * (ReplDiffSidebar diffBaseLabel), or null for none.
8 *
9 * Hidden in settled session mode and before any fetch; the requested mode
10 * with an ellipsis while its fetch is pending; on an unborn HEAD with
11 * rows, what the rows are instead.
12 *
13 * @param requested the mode the person picked
14 * @param data the last good fetch
15 * @param filesCount the header's session file count
16 * @param words the backend's words
17 * @returns the line, or null
18 */
19export function baseLabelOf(
20 requested: Git.BaseMode,
21 data: Git.DiffData | null,
22 filesCount: number,
23 words: Pick<Backend.BackendWords, 'base'>,
24): string | null {
25 if (!data) {
26 return null
27 }
28
29 if (data.isUnborn) {
30 const hasRows = filesCount > 0
31
32 return hasRows ? 'no commits yet — showing staged and new files' : null
33 }
34
35 const isPending = requested !== data.mode
36 const isSettledSession = !isPending && requested === 'session'
37
38 if (isSettledSession) {
39 return null
40 }
41
42 const phase = isPending ? 'pending' : 'settled'
43 const label = modeLabelOf(requested, data.source, phase, words)
44
45 return isPending ? `${label}…` : label
46}