Skip to content

feat(switch): accept pr:N/mr:N in --base - #2263

Merged
max-sixty merged 5 commits into
mainfrom
feat/base-pr-mr-shortcut
Apr 17, 2026
Merged

feat(switch): accept pr:N/mr:N in --base#2263
max-sixty merged 5 commits into
mainfrom
feat/base-pr-mr-shortcut

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

Route --base through the same pr:N/mr:N resolution used for the positional branch argument, so these two commands now work symmetrically:

wt switch -c feat-x pr:42          # already worked
wt switch -c feat-x --base pr:42   # new

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) or refs/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 name
  • test_switch_base_pr_fork — fork PR resolves to commit SHA, no tracking branch created
  • test_switch_base_mr_same_repo — same-repo GitLab MR
  • test_switch_base_pr_without_create — warning (no fetch) when --create absent
  • cargo test --test integration (1478 tests pass)
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check

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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/commands/worktree/switch.rs Outdated
Comment thread src/commands/worktree/switch.rs Outdated
Both callers discard it with `?`. Simplify to `Result<()>` and update
the docstring.
Comment thread skills/worktrunk/reference/switch.md Outdated
worktrunk-bot and others added 2 commits April 17, 2026 01:53
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>
@max-sixty
max-sixty merged commit 1d01a25 into main Apr 17, 2026
24 checks passed
@max-sixty
max-sixty deleted the feat/base-pr-mr-shortcut branch April 17, 2026 04:46
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.

Support pr:/mr: shortcuts in --base flag

2 participants