Skip to content

BBC2-13 add bb pr checkout (same-repo PRs only)#20

Open
b2l wants to merge 1 commit into
mainfrom
bbc2-13-pr-checkout
Open

BBC2-13 add bb pr checkout (same-repo PRs only)#20
b2l wants to merge 1 commit into
mainfrom
bbc2-13-pr-checkout

Conversation

@b2l
Copy link
Copy Markdown
Owner

@b2l b2l commented Apr 22, 2026

Summary

  • New bb pr checkout <id> that fetches the PR's source branch and either creates a local tracking branch or fast-forwards an existing one
  • Fork-based PRs are detected (source vs destination repository.full_name) and refused with a clear error — full fork support is explicitly out of scope per the ticket
  • Extends GitRunner with the write primitives fetchRef, checkoutExistingBranch, checkoutCreateTracking, mergeFastForwardOnly, plus the query hasLocalBranch. Failed writes throw a new GitError whose message carries git's stderr — the user sees git's own diagnostics (dirty working tree, diverged branches, missing remote ref) rather than a paraphrase.
  • Extends PullRequestDetail with sourceRepositoryFullName / destinationRepositoryFullName so the fork check reads from the same typed GET /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 lint clean
  • bunx tsc --noEmit clean
  • Manual: bb pr checkout --help shows correct help
  • Manual: bb pr checkout (no id) errors with commander's required-arg message
  • Manual: bb pr checkout abc / bb pr checkout 0 error with clear validation message

Manual test path

On any clone of a Bitbucket repo where you can see your own PRs:

  1. Pick an open same-repo PR whose source branch does NOT exist locally. Run bb pr checkout <N>. Expect: Checked out pull request #N: <branch>. — you're switched to a new local branch tracking origin/<branch>.
  2. Run bb pr checkout <N> again for the same PR. Expect: Checked out pull request #N: <branch> (fast-forwarded). — idempotent when nothing has changed remotely.
  3. Make a local commit on that branch, then run bb pr checkout <N> once more. Expect a GitError with git's own "Not possible to fast-forward" output (we don't force).
  4. On a dirty working tree (uncommitted changes overlapping with the target branch), run bb pr checkout <different-N>. Expect git's "Your local changes to the following files would be overwritten by checkout" error, surfaced verbatim.
  5. If you can find a fork-based PR in your workspace, run 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.
  6. bb --json pr checkout <N> emits {"id": ..., "branch": "...", "action": "created" | "fast-forwarded"}.

Closes BBC2-13.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant