feat: add pr diff and checkout (task 0014) #14
Reference in New Issue
Block a user
Delete Branch "task-0014-pr-diff-and-checkout"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements
.claude/tasks/0014-pr-diff-and-checkout.md.Summary
Adds the two PR commands that touch content and the local worktree:
pr diff <n>fetches the raw diff from the.diffendpoint (forcing a text response — the JSON-defaulting client would otherwise discard the plain-text body), truncating at 4000 chars with separatetruncated/original_lengthfields and a prepended--fullsuggestion;--fullreturns the raw diff.pr checkout <n>reads the PR head branch from the PR fetch and fetchesrefs/pull/{n}/headfrom origin (uniform for same-repo and fork PRs, per ADR 0011), three-cased on local branch state so re-checkout is idempotent; divergent local commits fail withGIT_ERRORrather than being discarded.Introduces the
GIT_ERRORmapping (runGit) carrying git's first stderr line plus a remediation help line, extends the test fixture server with araw(non-JSON) response body, and widens the PR 404 classifier so a.diffpath still resolves toPR_NOT_FOUND.Deviations
.difffetch forces{ format: "text" }becausegiteaApisetsbaseApiParams.format: "json", which would otherwise null out the plain-text body.merge --ff-onlyprintshint:lines before thefatal:line, so the surfacedGIT_ERRORmessage is that firsthint:line; the plain-language divergence explanation lives in the help lines (matching the spec's literal "git's first stderr line")./implementfront-loaded the implementation before the test-writer sub-agent authored tests, so TDD cycles were green-on-first-run; each test was still authored independently by a sub-agent from the public CLI interface alone, one behavior at a time.Review
Risk
Overall: Medium
errors.tsand an optionalrawfield in the test fixture server, neither altering existing callers.pr checkoutmutates the working tree via git and force-updates local branches, but only branches it defines as PR-head mirrors, and refuses to discard divergent local commits (--ff-only).checkoutPullHead(three-way branch-state casing plus fast-forward error handling).Standards — unaddressed findings
checkoutPullHeadthreads a barenumber+branchand builds thepull/{n}/headrefspecs by hand. Left as-is — the "PR head ref" concept is local and used once, so a dedicated type would be speculative; the reviewer explicitly would not act on it.(The Duplicated-Code finding — the
merge --ff-onlypath re-implementingrunGit's failure mapping — was fixed in this diff:runGitgained an optional fallback message and the merge routes through it.)Spec
No unaddressed findings — the Spec axis reported the change faithfully implements the task, spec, and ADR 0011 with no defects.
Add the two PR commands that touch content and the local worktree: - `pr diff <n>` fetches the raw diff from the `.diff` endpoint (forcing a text response, which the JSON-defaulting client would otherwise discard), truncates at 4000 chars with separate `truncated`/`original_length` fields and a prepended `--full` suggestion; `--full` returns the raw diff. - `pr checkout <n>` reads the PR head branch from the PR fetch and fetches `refs/pull/{n}/head` from origin (uniform for same-repo and fork PRs, ADR 0011), three-cased on local branch state so re-checkout is idempotent and divergent local commits fail with `GIT_ERROR` rather than being discarded. Introduces the `GIT_ERROR` mapping (`runGit`) carrying git's first stderr line plus a remediation help line, and widens the PR 404 classifier so a `.diff` path still resolves to `PR_NOT_FOUND`.