返回 DeepSeek-Reasonix
workspaceChanges.ts
根目录 / desktop / frontend / src / lib / workspaceChanges.ts
1 import type { Translator } from "./i18n";
2 import type { DictKey } from "../locales/en";
3
4 // git-status(1) "Unmerged" table: DD/AU/UD/UA/DU/AA/UU. AA and DD carry no U,
5 // so they must be matched as whole codes before the per-letter fallbacks.
6 const UNMERGED = new Set(["DD", "AU", "UD", "UA", "DU", "AA", "UU"]);
7
8 export function workspaceGitStatusLabelKey(status?: string): DictKey | null {
9 const s = (status ?? "").trim();
10 if (!s) return null;
11 if (s === "??") return "workspace.gitStatusUntracked";
12 if (UNMERGED.has(s)) return "workspace.gitStatusUnmerged";
13 if (s.includes("R")) return "workspace.gitStatusRenamed";
14 if (s.includes("C")) return "workspace.gitStatusCopied";
15 if (s.includes("D")) return "workspace.gitStatusDeleted";
16 if (s.includes("A")) return "workspace.gitStatusAdded";
17 if (s.includes("M")) return "workspace.gitStatusModified";
18 return null;
19 }
20
21 /** Porcelain status code as a reader-facing label; unknown codes pass through. */
22 export function workspaceGitStatusLabel(status: string | undefined, t: Translator): string {
23 const key = workspaceGitStatusLabelKey(status);
24 return key ? t(key) : (status ?? "").trim();
25 }
26
26 lines TYPESCRIPT