morphbox
Version:
Docker-based AI sandbox for development with Claude integration
34 lines (31 loc) • 1.28 kB
JavaScript
import { j as json } from './index-3BbzJtgI.js';
import { exec } from 'child_process';
import { promisify } from 'util';
import { W as WORKSPACE_DIR } from './workspace-CcQOwpY7.js';
import 'fs';
import 'path';
const execAsync = promisify(exec);
const POST = async ({ request }) => {
try {
const { message } = await request.json();
if (!message) {
return json({ error: "Commit message is required" }, { status: 400 });
}
const { stdout: status } = await execAsync("git status --porcelain", { cwd: WORKSPACE_DIR });
const stagedFiles = status.split("\n").filter(
(line) => line.length > 0 && (line[0] !== " " && line[0] !== "?")
);
if (stagedFiles.length === 0) {
return json({ error: "No staged changes to commit" }, { status: 400 });
}
const escapedMessage = message.replace(/"/g, '\\"');
const { stdout, stderr } = await execAsync(`git commit -m "${escapedMessage}"`, { cwd: WORKSPACE_DIR });
return json({ success: true, output: stdout });
} catch (error) {
console.error("Git commit error:", error);
const errorMessage = error.stderr || error.message || "Failed to commit";
return json({ error: errorMessage }, { status: 500 });
}
};
export { POST };
//# sourceMappingURL=_server.ts-CmEjWGsD.js.map