feat(switch): accept pr:N/mr:N in --base - #2263
Merged
Merged
Conversation
Route --base through the same pr:/mr: resolution used for the branch argument, so `wt switch -c feat-x --base pr:42` works symmetrically with `wt switch -c feat-x pr:42`. Same-repo PRs/MRs fetch the source branch and use it as the base by name. Fork PRs/MRs fetch refs/pull/N/head (or refs/merge-requests/N/head on GitLab) and use the resolved commit SHA, avoiding polluting the local branch namespace with a tracking branch for a fork's contributor. Closes #2261
Collapsed the multi-line `with_context(|| { cformat\!(...) })` in
`resolve_remote_ref_as_base` onto a single line. LLVM's coverage regions
inside a multi-line closure body were reported by codecov as uncovered
by happy-path tests; a single-line closure matches the pattern used in
`fetch_same_repo_branch` and coverage tracks it as covered.
worktrunk-bot
commented
Apr 16, 2026
worktrunk-bot
left a comment
Collaborator
Author
There was a problem hiding this comment.
fetch_same_repo_branch returns the remote name, but both callers discard it with ?. Consider dropping the return value to match actual use — otherwise the docstring's "Returns the remote name on success" is misleading.
Both callers discard it with `?`. Simplify to `Result<()>` and update the docstring.
max-sixty
reviewed
Apr 17, 2026
Per review feedback, always use `=` form for flag values in examples. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The new `resolve_base_ref` / `resolve_remote_ref_as_base` docstrings restated what the code already expresses; shorten to one-liners that carry only the non-obvious "why" (no tracking branch for fork refs). Invert the `is_cross_repo` check so the same-repo path early-returns and the fork path sits at function scope instead of inside `else`. Drops a few local comments that paraphrased the next line. Behavior, output, and snapshots are unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
3 tasks
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
Route
--basethrough the samepr:N/mr:Nresolution used for the positional branch argument, so these two commands now work symmetrically:Same-repo PRs/MRs fetch the source branch and use the branch name as the base, so the resulting worktree tracks it naturally. Fork PRs/MRs fetch
refs/pull/N/head(GitHub) orrefs/merge-requests/N/head(GitLab) and use the resolved commit SHA as the base — avoiding polluting the local branch namespace with a tracking branch for a fork contributor's branch.Closes #2261
Test plan
test_switch_base_pr_same_repo— same-repo PR resolves to source branch nametest_switch_base_pr_fork— fork PR resolves to commit SHA, no tracking branch createdtest_switch_base_mr_same_repo— same-repo GitLab MRtest_switch_base_pr_without_create— warning (no fetch) when--createabsentcargo test --test integration(1478 tests pass)cargo clippy --all-targets --all-features -- -D warningscargo fmt --all -- --check