diff --git a/src/cli.ts b/src/cli.ts index 0f6b389..41a34ce 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -391,6 +391,45 @@ program } }) +// ── sandlot show ─────────────────────────────────────────── + +program + .command("show") + .argument("", "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 ──────────────────────────────────────────── program