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 / empty-state-of.ts
69 lines · 1.9 KBRaw
1import type Backend from '../backend'
2import type Git from '../git'
3import Names from '../names'
4import type { EmptyState } from './empty-state'
5
6/**
7 * The headline that replaces the count when nothing is listed, worded as
8 * ReplDiffSidebar words it, keyed on the mode the data was FETCHED in.
9 *
10 * Null while there are files to count. No data after a settled fetch is
11 * "Diff unavailable"; no tracked rows while the untracked listing was
12 * withheld claims nothing about new files.
13 *
14 * @param data the last good fetch, or null when none ever settled
15 * @param filesCount the header's session file count
16 * @param words the backend's words
17 * @returns the empty state, or null
18 */
19export function emptyStateOf(
20 data: Git.DiffData | null,
21 filesCount: number,
22 words: Backend.BackendWords,
23): EmptyState | null {
24 if (!data) {
25 return {
26 headline: 'Diff unavailable',
27 hint: `Couldn't read the ${words.diffCommand} — it will retry on the next change`,
28 }
29 }
30
31 if (filesCount > 0) {
32 return null
33 }
34
35 if (data.isUntrackedWithheld) {
36 return {
37 headline: 'No tracked changes',
38 hint: Names.untrackedWithheldTextOf(words.lister),
39 }
40 }
41
42 if (data.isUnborn) {
43 return {
44 headline: 'No commits yet',
45 hint: "Nothing to diff against until the repo's first commit",
46 }
47 }
48
49 switch (data.mode) {
50 case 'uncommitted':
51 return { headline: 'No uncommitted changes', hint: null }
52 case 'branch':
53 if (data.source.kind === 'branch') {
54 return {
55 headline: `No changes vs ${data.source.baseBranch}`,
56 hint: null,
57 }
58 }
59
60 return {
61 headline: `No changes vs ${data.source.base}`,
62 hint:
63 'No base branch to compare against — showing changes vs ' +
64 data.source.base,
65 }
66 case 'session':
67 return { headline: 'No changes this session', hint: null }
68 }
69}