diff --git a/src/cli.ts b/src/cli.ts index 192f069..2ebc82a 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -333,21 +333,37 @@ program process.exit(1) } + let diff: string if (status.text().trim().length > 0) { // Show uncommitted changes (both staged and unstaged) - const result = await $`git -C ${session.worktree} diff --color=always HEAD`.nothrow() + const result = await $`git -C ${session.worktree} diff --color=always HEAD`.nothrow().quiet() if (result.exitCode !== 0) { // HEAD may not exist yet (no commits); fall back to showing all tracked + untracked - await $`git -C ${session.worktree} diff --color=always`.nothrow() + const fallback = await $`git -C ${session.worktree} diff --color=always`.nothrow().quiet() + diff = fallback.text() + } else { + diff = result.text() } } else { // No uncommitted changes — show full branch diff vs main const main = await git.mainBranch(root) - const result = await $`git -C ${session.worktree} diff --color=always ${main}...${branch}`.nothrow() + 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) } + diff = result.text() + } + + const lines = diff.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(diff) + pager.stdin.end() + await pager.exited + } else { + process.stdout.write(diff) } })