MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / gitStatus

Function gitStatus

src/workspaces/git-service.ts:65–86  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

63 * empty when in detached-HEAD; status files use porcelain v1 (XY path).
64 */
65export async function gitStatus(cwd: string): Promise<GitStatus> {
66 const [branchRes, statusRes] = await Promise.all([
67 exec(['branch', '--show-current'], cwd, gitOpts()).catch(() => null),
68 exec(['status', '--porcelain=v1'], cwd, gitOpts()),
69 ]);
70 if (statusRes.exitCode !== 0) {
71 throw new Error(`git status exited ${statusRes.exitCode}: ${statusRes.stderr.slice(0, 200)}`);
72 }
73 const branchRaw = branchRes && branchRes.exitCode === 0 ? branchRes.stdout.trim() : '';
74 const branch = branchRaw.length > 0 ? branchRaw : null;
75 const files: GitStatusFile[] = statusRes.stdout
76 .split('\n')
77 .filter((l) => l.length > 0)
78 .map((line) => ({
79 status: line.slice(0, 2),
80 // Porcelain emits 3-byte prefix `XY ` then the path. Rename rows have a
81 // `->` separator; for v1's simple panel we keep the original line as-is
82 // after the prefix.
83 path: line.slice(3),
84 }));
85 return { branch, clean: files.length === 0, files };
86}

Callers 1

createWorkspaceRoutesFunction · 0.85

Calls 2

gitOptsFunction · 0.85
execFunction · 0.50

Tested by

no test coverage detected