Add sandlot show command to display prompt and diff for a branch
This commit is contained in:
parent
e5085d50ed
commit
f47dabbabc
39
src/cli.ts
39
src/cli.ts
|
|
@ -390,6 +390,45 @@ program
|
|||
}
|
||||
})
|
||||
|
||||
// ── sandlot show <branch> ───────────────────────────────────────────
|
||||
|
||||
program
|
||||
.command("show")
|
||||
.argument("<branch>", "branch name")
|
||||
.description("Show the prompt and full diff for a branch (for code review)")
|
||||
.action(async (branch: string) => {
|
||||
const root = await git.repoRoot()
|
||||
const session = await state.getSession(root, branch)
|
||||
if (!session) {
|
||||
console.error(`No session found for branch "${branch}".`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const main = await git.mainBranch(root)
|
||||
const result = await $`git -C ${session.worktree} diff --color=always ${main}...${branch}`.nothrow().quiet()
|
||||
if (result.exitCode !== 0) {
|
||||
console.error("git diff failed")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
let output = ""
|
||||
if (session.prompt) {
|
||||
output += `PROMPT: ${session.prompt}\n\n`
|
||||
}
|
||||
output += result.text()
|
||||
|
||||
const lines = output.split("\n").length
|
||||
const termHeight = process.stdout.rows || 24
|
||||
if (lines > termHeight) {
|
||||
const pager = Bun.spawn(["less", "-R"], { stdin: "pipe", stdout: "inherit", stderr: "inherit" })
|
||||
pager.stdin.write(output)
|
||||
pager.stdin.end()
|
||||
await pager.exited
|
||||
} else {
|
||||
process.stdout.write(output)
|
||||
}
|
||||
})
|
||||
|
||||
// ── sandlot log <branch> ────────────────────────────────────────────
|
||||
|
||||
program
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user