MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / parsePorcelain

Function parsePorcelain

packages/agent-core/src/services/fs/fsGit.ts:39–76  ·  view source on GitHub ↗
(
  stdout: string,
  filter: Set<string> | undefined,
)

Source from the content-addressed store, hash-verified

37export const IFsGitService = createDecorator<IFsGitService>('fsGitService');
38
39export function parsePorcelain(
40 stdout: string,
41 filter: Set<string> | undefined,
42): FsGitStatusResponse {
43 const lines = stdout.split('\n');
44 let branch = '';
45 let ahead = 0;
46 let behind = 0;
47 const entries: Record<string, FsGitStatus> = {};
48
49 for (const line of lines) {
50 if (line.length === 0) continue;
51 if (line.startsWith('## ')) {
52 const parsed = parseBranchHeader(line.slice(3));
53 branch = parsed.branch;
54 ahead = parsed.ahead;
55 behind = parsed.behind;
56 continue;
57 }
58
59 if (line.length < 4) continue;
60 const xy = line.slice(0, 2);
61 let rest = line.slice(3);
62
63 if (xy.startsWith('R') || xy.startsWith('C')) {
64 const arrow = rest.indexOf(' -> ');
65 if (arrow >= 0) {
66 rest = rest.slice(arrow + 4);
67 }
68 }
69 const wirePath = posix(rest.trim());
70 if (filter !== undefined && !filter.has(wirePath)) continue;
71 const status = collapseXY(xy);
72 entries[wirePath] = status;
73 }
74
75 return { branch, ahead, behind, entries, additions: 0, deletions: 0, pullRequest: null };
76}
77
78/**
79 * Sum added/deleted line counts from `git diff --numstat` output. Each line is

Callers 2

statusMethod · 0.90
fs-git.e2e.test.tsFile · 0.90

Calls 4

parseBranchHeaderFunction · 0.85
posixFunction · 0.85
collapseXYFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected