MCPcopy
hub / github.com/coder/mux / parseGitStatusScriptOutput

Function parseGitStatusScriptOutput

src/common/utils/git/gitStatus.ts:136–177  ·  view source on GitHub ↗
(output: string)

Source from the content-addressed store, hash-verified

134}
135
136export function parseGitStatusScriptOutput(output: string): ParsedGitStatusOutput | null {
137 // Split by section markers using regex to get content between markers
138 const headBranchRegex = /---HEAD_BRANCH---\s*([\s\S]*?)---PRIMARY---/;
139 const primaryRegex = /---PRIMARY---\s*([\s\S]*?)---AHEAD_BEHIND---/;
140 const aheadBehindRegex = /---AHEAD_BEHIND---\s*(\d+)\s+(\d+)/;
141 const dirtyRegex = /---DIRTY---\s*(\d+)/;
142 const lineDeltaRegex = /---LINE_DELTA---\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
143
144 const headBranchMatch = headBranchRegex.exec(output);
145 const primaryMatch = primaryRegex.exec(output);
146 const aheadBehindMatch = aheadBehindRegex.exec(output);
147 const dirtyMatch = dirtyRegex.exec(output);
148 const lineDeltaMatch = lineDeltaRegex.exec(output);
149
150 if (!primaryMatch || !aheadBehindMatch || !dirtyMatch) {
151 return null;
152 }
153
154 const ahead = parseInt(aheadBehindMatch[1], 10);
155 const behind = parseInt(aheadBehindMatch[2], 10);
156
157 if (Number.isNaN(ahead) || Number.isNaN(behind)) {
158 return null;
159 }
160
161 const outgoingAdditions = lineDeltaMatch ? parseInt(lineDeltaMatch[1], 10) : 0;
162 const outgoingDeletions = lineDeltaMatch ? parseInt(lineDeltaMatch[2], 10) : 0;
163 const incomingAdditions = lineDeltaMatch ? parseInt(lineDeltaMatch[3], 10) : 0;
164 const incomingDeletions = lineDeltaMatch ? parseInt(lineDeltaMatch[4], 10) : 0;
165
166 return {
167 headBranch: headBranchMatch ? headBranchMatch[1].trim() : "",
168 primaryBranch: primaryMatch[1].trim(),
169 ahead,
170 behind,
171 dirtyCount: parseInt(dirtyMatch[1], 10),
172 outgoingAdditions,
173 outgoingDeletions,
174 incomingAdditions,
175 incomingDeletions,
176 };
177}
178
179/**
180 * Smart git fetch script that minimizes lock contention.

Callers 4

checkWorkspaceStatusMethod · 0.90
testGitStatusFunction · 0.90
getProjectGitStatusesMethod · 0.90

Calls 1

execMethod · 0.65

Tested by

no test coverage detected