BBC2-13 add bb pr checkout (same-repo PRs only)#20
Open
b2l wants to merge 1 commit into
Open
Conversation
Fetches the PR's source branch via `git fetch origin <branch>`, then either creates a local tracking branch or fast-forwards an existing one. Fork-based PRs are detected by comparing source vs destination repository.full_name on the PR response and rejected with a clear error — full fork support is out of scope for this ticket. Extends the GitRunner interface with fetchRef, hasLocalBranch, checkout (create-tracking / existing), and mergeFastForwardOnly primitives. Writes throw a new GitError whose message carries git's stderr, so the user sees git's own diagnostics for dirty working trees, diverged branches, etc. Extends PullRequestDetail with sourceRepositoryFullName and destinationRepositoryFullName so the fork check reads from the same typed response rather than a separate call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bb pr checkout <id>that fetches the PR's source branch and either creates a local tracking branch or fast-forwards an existing onerepository.full_name) and refused with a clear error — full fork support is explicitly out of scope per the ticketGitRunnerwith the write primitivesfetchRef,checkoutExistingBranch,checkoutCreateTracking,mergeFastForwardOnly, plus the queryhasLocalBranch. Failed writes throw a newGitErrorwhose message carries git's stderr — the user sees git's own diagnostics (dirty working tree, diverged branches, missing remote ref) rather than a paraphrase.PullRequestDetailwithsourceRepositoryFullName/destinationRepositoryFullNameso the fork check reads from the same typedGET /pullrequests/{id}response.Test plan
bun test— all 165 tests pass (added 10 integration tests against a real local bare remote covering fetch/hasLocalBranch/checkout/ff, happy + failure paths; added 2 backend mapping tests for the new fields)bun run lintcleanbunx tsc --noEmitcleanbb pr checkout --helpshows correct helpbb pr checkout(no id) errors with commander's required-arg messagebb pr checkout abc/bb pr checkout 0error with clear validation messageManual test path
On any clone of a Bitbucket repo where you can see your own PRs:
bb pr checkout <N>. Expect:Checked out pull request #N: <branch>.— you're switched to a new local branch trackingorigin/<branch>.bb pr checkout <N>again for the same PR. Expect:Checked out pull request #N: <branch> (fast-forwarded).— idempotent when nothing has changed remotely.bb pr checkout <N>once more. Expect aGitErrorwith git's own "Not possible to fast-forward" output (we don't force).bb pr checkout <different-N>. Expect git's "Your local changes to the following files would be overwritten by checkout" error, surfaced verbatim.bb pr checkout <N>. Expect:Pull request source repo 'other-ws/repo' differs from '<your-ws/repo>'. Fork-based PR checkout is not supported yet — open a follow-up if you need this.bb --json pr checkout <N>emits{"id": ..., "branch": "...", "action": "created" | "fast-forwarded"}.Closes BBC2-13.