Skip to content

Commit 4b68046

Browse files
committed
fix: surface raw git stdout/stderr in git_push and batch_commit responses
1 parent 1201f1e commit 4b68046

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

src/server/batch-commit-tool.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface CommitResult {
3131
files: string[];
3232
error?: string;
3333
detail?: string;
34+
output?: string;
3435
}
3536

3637
export interface PushReport {
@@ -39,6 +40,7 @@ export interface PushReport {
3940
upstream?: string;
4041
error?: string;
4142
detail?: string;
43+
output?: string;
4244
}
4345

4446
/**
@@ -66,7 +68,13 @@ export async function runPushAfter(gitTop: string): Promise<PushReport> {
6668
detail: (pushResult.stderr || pushResult.stdout).trim(),
6769
};
6870
}
69-
return { ok: true, branch, upstream: t.upstream };
71+
const gitOutput = (pushResult.stdout || pushResult.stderr).trim();
72+
return {
73+
ok: true,
74+
branch,
75+
upstream: t.upstream,
76+
...spreadDefined("output", gitOutput || undefined),
77+
};
7078
}
7179

7280
export function registerBatchCommitTool(server: FastMCP): void {
@@ -124,39 +132,45 @@ export function registerBatchCommitTool(server: FastMCP): void {
124132
// --- Stage files ---
125133
const addResult = await spawnGitAsync(gitTop, ["add", "--", ...entry.files]);
126134
if (!addResult.ok) {
135+
const gitOutput = (addResult.stderr || addResult.stdout).trim();
127136
results.push({
128137
index: i,
129138
ok: false,
130139
message: entry.message,
131140
files: entry.files,
132141
error: "stage_failed",
133-
detail: (addResult.stderr || addResult.stdout).trim(),
142+
detail: gitOutput,
143+
...spreadDefined("output", gitOutput || undefined),
134144
});
135145
break;
136146
}
137147

138148
// --- Commit ---
139149
const commitResult = await spawnGitAsync(gitTop, ["commit", "-m", entry.message]);
140150
if (!commitResult.ok) {
151+
const gitOutput = (commitResult.stderr || commitResult.stdout).trim();
141152
results.push({
142153
index: i,
143154
ok: false,
144155
message: entry.message,
145156
files: entry.files,
146157
error: "commit_failed",
147-
detail: (commitResult.stderr || commitResult.stdout).trim(),
158+
detail: gitOutput,
159+
...spreadDefined("output", gitOutput || undefined),
148160
});
149161
break;
150162
}
151163

152164
// --- Extract SHA from commit output ---
153165
const shaMatch = /\[[\w/.-]+\s+([0-9a-f]+)\]/.exec(commitResult.stdout);
166+
const gitOutput = (commitResult.stdout || commitResult.stderr).trim();
154167
results.push({
155168
index: i,
156169
ok: true,
157170
sha: shaMatch?.[1],
158171
message: entry.message,
159172
files: entry.files,
173+
...spreadDefined("output", gitOutput || undefined),
160174
});
161175
}
162176

@@ -179,6 +193,7 @@ export function registerBatchCommitTool(server: FastMCP): void {
179193
files: r.files,
180194
...spreadDefined("error", r.error),
181195
...spreadDefined("detail", r.detail),
196+
...spreadDefined("output", r.output),
182197
})),
183198
...spreadWhen(push !== undefined, {
184199
push: {
@@ -187,6 +202,7 @@ export function registerBatchCommitTool(server: FastMCP): void {
187202
...spreadDefined("upstream", push?.upstream),
188203
...spreadDefined("error", push?.error),
189204
...spreadDefined("detail", push?.detail),
205+
...spreadDefined("output", push?.output),
190206
},
191207
}),
192208
});
@@ -206,6 +222,9 @@ export function registerBatchCommitTool(server: FastMCP): void {
206222
if (!r.ok && r.detail) {
207223
lines.push(` Error: ${r.error}${r.detail}`);
208224
}
225+
if (r.output) {
226+
lines.push(` Output: ${r.output.replace(/\n/g, "\n ")}`);
227+
}
209228
}
210229

211230
if (!allOk && results.length < args.commits.length) {
@@ -220,6 +239,9 @@ export function registerBatchCommitTool(server: FastMCP): void {
220239
} else {
221240
lines.push(`Push: ✗ ${push.error}${push.detail ? ` — ${push.detail}` : ""}`);
222241
}
242+
if (push.output) {
243+
lines.push(` Output: ${push.output.replace(/\n/g, "\n ")}`);
244+
}
223245
}
224246

225247
return lines.join("\n");

src/server/git-push-tool.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,25 @@ export function registerGitPushTool(server: FastMCP): void {
106106
]);
107107
const upstream = upstreamProbe.ok ? upstreamProbe.stdout.trim() : `${remote}/${branch}`;
108108

109+
// Append git output (stdout/stderr) if non-empty
110+
const gitOutput = (pushResult.stdout || pushResult.stderr).trim();
111+
109112
if (args.format === "json") {
110113
return jsonRespond({
111114
ok: true,
112115
branch,
113116
remote,
114117
upstream,
115118
...spreadDefined("setUpstream", args.setUpstream || undefined),
119+
...spreadDefined("output", gitOutput || undefined),
116120
});
117121
}
118122

119-
return `# Push\n✓ ${branch}${upstream}`;
123+
let result = `# Push\n✓ ${branch}${upstream}`;
124+
if (gitOutput) {
125+
result += `\n\n${gitOutput}`;
126+
}
127+
return result;
120128
},
121129
});
122130
}

0 commit comments

Comments
 (0)