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

Function parseBranchHeader

packages/agent-core/src/services/fs/fsGit.ts:104–133  ·  view source on GitHub ↗
(rest: string)

Source from the content-addressed store, hash-verified

102}
103
104function parseBranchHeader(rest: string): {
105 branch: string;
106 ahead: number;
107 behind: number;
108} {
109
110 if (rest.startsWith('HEAD (no branch)')) {
111 return { branch: '', ahead: 0, behind: 0 };
112 }
113 if (rest.startsWith('No commits yet on ')) {
114 return { branch: rest.slice('No commits yet on '.length), ahead: 0, behind: 0 };
115 }
116 let branch = rest;
117 let ahead = 0;
118 let behind = 0;
119
120 const bracket = rest.indexOf(' [');
121 if (bracket >= 0) {
122 branch = rest.slice(0, bracket);
123 const sliced = rest.slice(bracket + 2, rest.length - 1);
124 const aheadMatch = sliced.match(/ahead (\d+)/);
125 const behindMatch = sliced.match(/behind (\d+)/);
126 if (aheadMatch !== null) ahead = Number.parseInt(aheadMatch[1] ?? '0', 10) || 0;
127 if (behindMatch !== null) behind = Number.parseInt(behindMatch[1] ?? '0', 10) || 0;
128 }
129
130 const dots = branch.indexOf('...');
131 if (dots >= 0) branch = branch.slice(0, dots);
132 return { branch, ahead, behind };
133}
134
135function collapseXY(xy: string): FsGitStatus {
136 if (xy === '??') return 'untracked';

Callers 1

parsePorcelainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected