allow optional manual commit message in sandlot save, skip AI generation when provided
This commit is contained in:
parent
ec697565ac
commit
9f250188ca
35
src/cli.ts
35
src/cli.ts
|
|
@ -146,8 +146,9 @@ program
|
|||
program
|
||||
.command("save")
|
||||
.argument("<branch>", "branch name")
|
||||
.description("Stage all changes and commit with an AI-generated message")
|
||||
.action(async (branch: string) => {
|
||||
.argument("[message]", "commit message (AI-generated if omitted)")
|
||||
.description("Stage all changes and commit")
|
||||
.action(async (branch: string, message?: string) => {
|
||||
const root = await git.repoRoot()
|
||||
const session = await state.getSession(root, branch)
|
||||
if (!session) {
|
||||
|
|
@ -169,27 +170,33 @@ program
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
spin.text = "Generating commit message"
|
||||
const gen = await vm.exec(
|
||||
worktreeAbs,
|
||||
'set -a; source ~/.env 2>/dev/null; set +a; git diff --staged | claude -p "write a short commit message summarizing these changes. output only the message, no quotes or extra text" > /tmp/sandlot_commit_msg',
|
||||
)
|
||||
if (gen.exitCode !== 0) {
|
||||
spin.fail("Failed to generate commit message")
|
||||
if (gen.stderr) console.error(gen.stderr)
|
||||
process.exit(1)
|
||||
let msg: string
|
||||
if (message) {
|
||||
msg = message
|
||||
} else {
|
||||
spin.text = "Generating commit message"
|
||||
const gen = await vm.exec(
|
||||
worktreeAbs,
|
||||
'set -a; source ~/.env 2>/dev/null; set +a; git diff --staged | claude -p "write a short commit message summarizing these changes. output only the message, no quotes or extra text" > /tmp/sandlot_commit_msg',
|
||||
)
|
||||
if (gen.exitCode !== 0) {
|
||||
spin.fail("Failed to generate commit message")
|
||||
if (gen.stderr) console.error(gen.stderr)
|
||||
process.exit(1)
|
||||
}
|
||||
const { stdout } = await vm.exec(worktreeAbs, "cat /tmp/sandlot_commit_msg")
|
||||
await vm.exec(worktreeAbs, "rm -f /tmp/sandlot_commit_msg")
|
||||
msg = stdout
|
||||
}
|
||||
|
||||
spin.text = "Committing"
|
||||
const commit = await vm.exec(worktreeAbs, "git commit -F /tmp/sandlot_commit_msg")
|
||||
const commit = await vm.exec(worktreeAbs, `git commit -m ${JSON.stringify(msg)}`)
|
||||
if (commit.exitCode !== 0) {
|
||||
spin.fail("Commit failed")
|
||||
if (commit.stderr) console.error(commit.stderr)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const { stdout: msg } = await vm.exec(worktreeAbs, "cat /tmp/sandlot_commit_msg")
|
||||
await vm.exec(worktreeAbs, "rm -f /tmp/sandlot_commit_msg")
|
||||
spin.succeed(`Saved: ${msg}`)
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user