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

Function readStatus

apps/kimi-code/src/utils/git/git-status.ts:172–214  ·  view source on GitHub ↗
(workDir: string)

Source from the content-addressed store, hash-verified

170}
171
172function readStatus(workDir: string): {
173 dirty: boolean;
174 ahead: number;
175 behind: number;
176 diffAdded: number;
177 diffDeleted: number;
178} {
179 try {
180 const result = spawnSync('git', ['-C', workDir, 'status', '--porcelain', '-b'], {
181 encoding: 'utf8',
182 timeout: SPAWN_TIMEOUT_MS,
183 maxBuffer: 4 * 1024 * 1024,
184 });
185 if (result.status !== 0) {
186 return { dirty: false, ahead: 0, behind: 0, diffAdded: 0, diffDeleted: 0 };
187 }
188
189 let dirty = false;
190 let ahead = 0;
191 let behind = 0;
192 for (const line of result.stdout.split('\n')) {
193 if (line.startsWith('## ')) {
194 const m = AHEAD_BEHIND_RE.exec(line);
195 if (m) {
196 ahead = Number.parseInt(m[1] ?? '0', 10) || 0;
197 behind = Number.parseInt(m[2] ?? '0', 10) || 0;
198 }
199 } else if (line.trim().length > 0) {
200 dirty = true;
201 }
202 }
203 const diff = dirty ? readDiffStats(workDir) : { added: 0, deleted: 0 };
204 return {
205 dirty,
206 ahead,
207 behind,
208 diffAdded: diff.added,
209 diffDeleted: diff.deleted,
210 };
211 } catch {
212 return { dirty: false, ahead: 0, behind: 0, diffAdded: 0, diffDeleted: 0 };
213 }
214}
215
216function readDiffStats(workDir: string): { added: number; deleted: number } {
217 try {

Callers 1

createGitStatusCacheFunction · 0.70

Calls 2

readDiffStatsFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected